]> code.delx.au - dotfiles/blob - .vim/macros.vim
Vim: Commenter supports lots more files
[dotfiles] / .vim / macros.vim
1 " Python Calculator
2 command! -nargs=+ Calc :r! python -c "from math import *; print <args>"
3
4 " I frequently type :Q or :WQ, etc instead of :q, :wq
5 command! WQA :wqa
6 command! WqA :wqa
7 command! WQa :wqa
8 command! Wqa :wqa
9 command! WA :wa
10 command! Wa :wa
11 command! WQ :wq
12 command! Wq :wq
13 command! W :w
14 command! Wn :wn
15 command! WN :wn
16 command! Wp :wp
17 command! WP :wp
18 command! QA :qa
19 command! Qa :qa
20 command! Q :q
21
22 " Unhighlight search results
23 nmap <C-l> :nohlsearch<CR>:redraw!<CR>
24
25 " Map Y to be consistent with D, C, etc
26 nmap Y y$
27
28 " CTRL-n and CTRL-p to go forwards and backwards through files
29 nmap <C-n> :next<CR>
30 nmap <C-p> :prev<CR>
31
32 " CTRL-J/K to move up and down, collapsing open windows
33 map <C-J> <C-W>j<C-W>_
34 map <C-K> <C-W>k<C-W>_
35
36 " Press CTRL-z after pasting something to fix up formatting
37 imap <C-z> <ESC>u:set paste<CR>.:set nopaste<CR>i
38
39 " Tab to switch between split windows
40 nmap <Tab> <C-w><C-w>
41
42 " Q to reformat paragraph. I never use ex mode anyway (default binding for Q)
43 nmap Q gwip
44
45
46 " Toggle wordwrap
47 function WrapToggle()
48 if &wrap
49 call WrapOff()
50 echo "Word wrap off"
51 else
52 call WrapOn()
53 echo "Word wrap on"
54 endif
55 endfunction
56 map <F10> :call WrapToggle()<CR>
57 imap <F10> <C-o>:call WrapToggle()<CR>
58
59 " Turn word wrap off, reset arrows, home, end, etc to default bindings
60 function WrapOff()
61 setlocal nowrap
62 " Go up and down by physical linebreaks when not wordwrapped
63 iunmap <buffer> <End>
64 iunmap <buffer> <Home>
65 iunmap <buffer> <Down>
66 iunmap <buffer> <Up>
67 nunmap <buffer> <Down>
68 nunmap <buffer> <Up>
69 nunmap <buffer> <End>
70 nunmap <buffer> <Home>
71 nunmap <buffer> 0
72 nunmap <buffer> ^
73 nunmap <buffer> $
74 " Allow only backspace & space
75 set whichwrap=b,s
76 endfunction
77
78 " Turn word wrapping on and bind arrows, home, end, etc to display lines
79 function WrapOn()
80 setlocal wrap
81 " Go up and down by display lines, not linebreaks when wordwrapped
82 imap <buffer> <End> <C-o>g$
83 imap <buffer> <Home> <C-o>g0
84 imap <buffer> <Down> <C-o>gj
85 imap <buffer> <Up> <C-o>gk
86 nmap <buffer> <Down> gj
87 nmap <buffer> <Up> gk
88 nmap <buffer> <End> g$
89 nmap <buffer> <Home> g0
90 nmap <buffer> 0 g0
91 nmap <buffer> ^ g^
92 nmap <buffer> $ g$
93 " Allow backspace, space, left/right keys to move across lines
94 set whichwrap=b,s,<,>,[,]
95 endfunction
96
97
98 " Toggle show invisible characters
99 function InvShow()
100 if &list
101 echo "Invisible characters off"
102 set nolist
103 else
104 echo "Invisible characters on"
105 set listchars=tab:.\ ,trail:!
106 set list
107 endif
108 endfunction
109 map <F9> :call InvShow()<CR>
110 imap <F9> <C-o>:call InvShow()<CR>
111
112
113 " Spell checking mode toggle
114 function ToggleSpelling()
115 if !exists("s:spell_check") || s:spell_check == 0
116 echo "Spell check on"
117 let s:spell_check = 1
118 setlocal spell spelllang=en_au
119 else
120 echo "Spell check off"
121 let s:spell_check = 0
122 setlocal spell spelllang=
123 endif
124 endfunction
125 map <F8> :call ToggleSpelling()<CR>
126 imap <F8> <C-o>:call ToggleSpelling()<CR>
127