]> code.delx.au - dotfiles/blob - .vim/macros.vim
vim: single space after full stop
[dotfiles] / .vim / macros.vim
1 " Function key mappings
2 map <F8> :call ToggleSpelling()<CR>
3 imap <F8> <C-o>:call ToggleSpelling()<CR>
4 map <F9> :call InvShow()<CR>
5 imap <F9> <C-o>:call InvShow()<CR>
6 map <F10> :call WrapToggle()<CR>
7 imap <F10> <C-o>:call WrapToggle()<CR>
8
9 " Python Calculator
10 command -nargs=+ Calc :r! python -c "from math import *; print <args>"
11
12 " Unhighlight search results and redraw the screen
13 nmap <C-l> :nohlsearch<CR>:redraw!<CR>
14
15 " Map Y to be consistent with D, C, etc
16 nmap Y y$
17
18 " CTRL-n and CTRL-p to go forwards and backwards through files
19 nmap <C-n> :next<CR>
20 nmap <C-p> :prev<CR>
21
22 " CTRL-J/K to move up and down, collapsing open windows
23 map <C-J> <C-W>j<C-W>_
24 map <C-K> <C-W>k<C-W>_
25
26 " Press CTRL-z after pasting something to fix up formatting
27 imap <C-z> <ESC>u:set paste<CR>.:set nopaste<CR>i
28
29 " Tab to switch between split windows
30 nmap <Tab> <C-w><C-w>
31 nmap <Esc>[Z <C-w>W
32
33 " Q to reformat paragraph. I never use ex mode anyway (default binding for Q)
34 nmap Q gwip
35
36 " Save using sudo
37 command SudoWrite call SudoWriteFunction()
38
39 " I frequently type :Q or :WQ, etc instead of :q, :wq
40 command WQA :wqa
41 command WqA :wqa
42 command WQa :wqa
43 command Wqa :wqa
44 command WA :wa
45 command Wa :wa
46 command WQ :wq
47 command Wq :wq
48 command W :w
49 command Wn :wn
50 command WN :wn
51 command Wp :wp
52 command WP :wp
53 command QA :qa
54 command Qa :qa
55 command Q :q
56
57 " Make the number pad work
58 map \eOX =
59 imap \eOX =
60 set t_KC=\eOp " 0
61 set t_KD=\eOq " 1
62 set t_KE=\eOr " 2
63 set t_KF=\eOs " 3
64 set t_KG=\eOt " 4
65 set t_KH=\eOu " 5
66 set t_KI=\eOv " 6
67 set t_KJ=\eOw " 7
68 set t_KK=\eOx " 8
69 set t_KL=\eOy " 9
70
71 " Toggle wordwrap
72 function WrapToggle()
73 if &wrap
74 call WrapOff()
75 echo "Word wrap off"
76 else
77 call WrapOn()
78 echo "Word wrap on"
79 endif
80 endfunction
81
82 " Turn word wrap off, reset arrows, home, end, etc to default bindings
83 function WrapOff()
84 setlocal nowrap
85 " Go up and down by physical linebreaks when not wordwrapped
86 iunmap <buffer> <End>
87 iunmap <buffer> <Home>
88 iunmap <buffer> <Down>
89 iunmap <buffer> <Up>
90 nunmap <buffer> <Down>
91 nunmap <buffer> <Up>
92 nunmap <buffer> <End>
93 nunmap <buffer> <Home>
94 nunmap <buffer> 0
95 nunmap <buffer> ^
96 nunmap <buffer> $
97 vunmap <buffer> <Down>
98 vunmap <buffer> <Up>
99 vunmap <buffer> <End>
100 vunmap <buffer> <Home>
101 vunmap <buffer> 0
102 vunmap <buffer> ^
103 vunmap <buffer> $
104 " Allow only backspace & space
105 set whichwrap=b,s
106 endfunction
107
108 " Turn word wrapping on and bind arrows, home, end, etc to display lines
109 function WrapOn()
110 setlocal wrap
111 " Go up and down by display lines, not linebreaks when wordwrapped
112 imap <buffer> <End> <C-o>g$
113 imap <buffer> <Home> <C-o>g0
114 imap <buffer> <Down> <C-o>gj
115 imap <buffer> <Up> <C-o>gk
116 nmap <buffer> <Down> gj
117 nmap <buffer> <Up> gk
118 nmap <buffer> <End> g$
119 nmap <buffer> <Home> g0
120 nmap <buffer> 0 g0
121 nmap <buffer> ^ g^
122 nmap <buffer> $ g$
123 vmap <buffer> <Down> gj
124 vmap <buffer> <Up> gk
125 vmap <buffer> <End> g$
126 vmap <buffer> <Home> g0
127 vmap <buffer> 0 g0
128 vmap <buffer> ^ g^
129 vmap <buffer> $ g$
130 " Allow backspace, space, left/right keys to move across lines
131 set whichwrap=b,s,<,>,[,]
132 endfunction
133
134
135 " Toggle show invisible characters
136 function InvShow()
137 if &list
138 echo "Invisible characters off"
139 set nolist
140 else
141 echo "Invisible characters on"
142 set listchars=tab:.\ ,trail:!
143 set list
144 endif
145 endfunction
146
147
148 " Spell checking mode toggle
149 function ToggleSpelling()
150 if !exists("s:spell_check") || s:spell_check == 0
151 echo "Spell check on"
152 let s:spell_check = 1
153 setlocal spell spelllang=en_au
154 else
155 echo "Spell check off"
156 let s:spell_check = 0
157 setlocal spell spelllang=
158 endif
159 endfunction
160
161
162 " Save using sudo
163 function SudoWriteFunction()
164 :w !sudo tee %
165 :e!
166 endfunction
167