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