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