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