]> code.delx.au - dotfiles/blob - .vim/macros.vim
Vim: Use display line macros for visual select.
[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 vunmap <buffer> <Down>
75 vunmap <buffer> <Up>
76 vunmap <buffer> <End>
77 vunmap <buffer> <Home>
78 vunmap <buffer> 0
79 vunmap <buffer> ^
80 vunmap <buffer> $
81 " Allow only backspace & space
82 set whichwrap=b,s
83 endfunction
84
85 " Turn word wrapping on and bind arrows, home, end, etc to display lines
86 function WrapOn()
87 setlocal wrap
88 " Go up and down by display lines, not linebreaks when wordwrapped
89 imap <buffer> <End> <C-o>g$
90 imap <buffer> <Home> <C-o>g0
91 imap <buffer> <Down> <C-o>gj
92 imap <buffer> <Up> <C-o>gk
93 nmap <buffer> <Down> gj
94 nmap <buffer> <Up> gk
95 nmap <buffer> <End> g$
96 nmap <buffer> <Home> g0
97 nmap <buffer> 0 g0
98 nmap <buffer> ^ g^
99 nmap <buffer> $ g$
100 vmap <buffer> <Down> gj
101 vmap <buffer> <Up> gk
102 vmap <buffer> <End> g$
103 vmap <buffer> <Home> g0
104 vmap <buffer> 0 g0
105 vmap <buffer> ^ g^
106 vmap <buffer> $ g$
107 " Allow backspace, space, left/right keys to move across lines
108 set whichwrap=b,s,<,>,[,]
109 endfunction
110
111
112 " Toggle show invisible characters
113 function InvShow()
114 if &list
115 echo "Invisible characters off"
116 set nolist
117 else
118 echo "Invisible characters on"
119 set listchars=tab:.\ ,trail:!
120 set list
121 endif
122 endfunction
123 map <F9> :call InvShow()<CR>
124 imap <F9> <C-o>:call InvShow()<CR>
125
126
127 " Spell checking mode toggle
128 function ToggleSpelling()
129 if !exists("s:spell_check") || s:spell_check == 0
130 echo "Spell check on"
131 let s:spell_check = 1
132 setlocal spell spelllang=en_au
133 else
134 echo "Spell check off"
135 let s:spell_check = 0
136 setlocal spell spelllang=
137 endif
138 endfunction
139 map <F8> :call ToggleSpelling()<CR>
140 imap <F8> <C-o>:call ToggleSpelling()<CR>
141