]> code.delx.au - dotfiles/blob - .vim/macros.vim
vim: example autocmd to adjust indent settings in files matching a path
[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
37 " I frequently type :Q or :WQ, etc instead of :q, :wq
38 command! WQA :wqa
39 command! WqA :wqa
40 command! WQa :wqa
41 command! Wqa :wqa
42 command! WA :wa
43 command! Wa :wa
44 command! WQ :wq
45 command! Wq :wq
46 command! W :w
47 command! Wn :wn
48 command! WN :wn
49 command! Wp :wp
50 command! WP :wp
51 command! QA :qa
52 command! Qa :qa
53 command! Q :q
54
55 " Make the number pad work
56 map \eOX =
57 imap \eOX =
58 set t_KC=\eOp " 0
59 set t_KD=\eOq " 1
60 set t_KE=\eOr " 2
61 set t_KF=\eOs " 3
62 set t_KG=\eOt " 4
63 set t_KH=\eOu " 5
64 set t_KI=\eOv " 6
65 set t_KJ=\eOw " 7
66 set t_KK=\eOx " 8
67 set t_KL=\eOy " 9
68
69 " Toggle wordwrap
70 function WrapToggle()
71 if &wrap
72 call WrapOff()
73 echo "Word wrap off"
74 else
75 call WrapOn()
76 echo "Word wrap on"
77 endif
78 endfunction
79
80 " Turn word wrap off, reset arrows, home, end, etc to default bindings
81 function WrapOff()
82 setlocal nowrap
83 " Go up and down by physical linebreaks when not wordwrapped
84 iunmap <buffer> <End>
85 iunmap <buffer> <Home>
86 iunmap <buffer> <Down>
87 iunmap <buffer> <Up>
88 nunmap <buffer> <Down>
89 nunmap <buffer> <Up>
90 nunmap <buffer> <End>
91 nunmap <buffer> <Home>
92 nunmap <buffer> 0
93 nunmap <buffer> ^
94 nunmap <buffer> $
95 vunmap <buffer> <Down>
96 vunmap <buffer> <Up>
97 vunmap <buffer> <End>
98 vunmap <buffer> <Home>
99 vunmap <buffer> 0
100 vunmap <buffer> ^
101 vunmap <buffer> $
102 " Allow only backspace & space
103 set whichwrap=b,s
104 endfunction
105
106 " Turn word wrapping on and bind arrows, home, end, etc to display lines
107 function WrapOn()
108 setlocal wrap
109 " Go up and down by display lines, not linebreaks when wordwrapped
110 imap <buffer> <End> <C-o>g$
111 imap <buffer> <Home> <C-o>g0
112 imap <buffer> <Down> <C-o>gj
113 imap <buffer> <Up> <C-o>gk
114 nmap <buffer> <Down> gj
115 nmap <buffer> <Up> gk
116 nmap <buffer> <End> g$
117 nmap <buffer> <Home> g0
118 nmap <buffer> 0 g0
119 nmap <buffer> ^ g^
120 nmap <buffer> $ g$
121 vmap <buffer> <Down> gj
122 vmap <buffer> <Up> gk
123 vmap <buffer> <End> g$
124 vmap <buffer> <Home> g0
125 vmap <buffer> 0 g0
126 vmap <buffer> ^ g^
127 vmap <buffer> $ g$
128 " Allow backspace, space, left/right keys to move across lines
129 set whichwrap=b,s,<,>,[,]
130 endfunction
131
132
133 " Toggle show invisible characters
134 function InvShow()
135 if &list
136 echo "Invisible characters off"
137 set nolist
138 else
139 echo "Invisible characters on"
140 set listchars=tab:.\ ,trail:!
141 set list
142 endif
143 endfunction
144
145
146 " Spell checking mode toggle
147 function ToggleSpelling()
148 if !exists("s:spell_check") || s:spell_check == 0
149 echo "Spell check on"
150 let s:spell_check = 1
151 setlocal spell spelllang=en_au
152 else
153 echo "Spell check off"
154 let s:spell_check = 0
155 setlocal spell spelllang=
156 endif
157 endfunction
158