]> code.delx.au - dotfiles/blobdiff - .vim/macros.vim
vim: Don't stay in visual mode after indent
[dotfiles] / .vim / macros.vim
index ba2b2036fce6792eecce2ebf97df3a56b0d9e3bc..c84c515e05d0e78be914b55a77da18950ec45d69 100644 (file)
@@ -1,25 +1,15 @@
+" Function key mappings
+map <F8> :call ToggleSpelling()<CR>
+imap <F8> <C-o>:call ToggleSpelling()<CR>
+map <F9> :call InvShow()<CR>
+imap <F9> <C-o>:call InvShow()<CR>
+map <F10> :call WrapToggle()<CR>
+imap <F10> <C-o>:call WrapToggle()<CR>
+
 " Python Calculator
-command! -nargs=+ Calc :r! python -c "from math import *; print <args>"
+command -nargs=+ Calc :r! python -c "from math import *; print <args>"
 
-" I frequently type :Q or :WQ, etc instead of :q, :wq
-command! WQA :wqa
-command! WqA :wqa
-command! WQa :wqa
-command! Wqa :wqa
-command! WA :wa
-command! Wa :wa
-command! WQ :wq
-command! Wq :wq
-command! W :w
-command! Wn :wn
-command! WN :wn
-command! Wp :wp
-command! WP :wp
-command! QA :qa
-command! Qa :qa
-command! Q :q
-
-" Unhighlight search results
+" Unhighlight search results and redraw the screen
 nmap <C-l> :nohlsearch<CR>:redraw!<CR>
 
 " Map Y to be consistent with D, C, etc
@@ -38,27 +28,125 @@ imap <C-z> <ESC>u:set paste<CR>.:set nopaste<CR>i
 
 " Tab to switch between split windows
 nmap <Tab> <C-w><C-w>
+nmap <Esc>[Z <C-w>W
 
 " Q to reformat paragraph. I never use ex mode anyway (default binding for Q)
 nmap Q gwip
 
-" Go up and down by display lines, not linebreaks
-imap <End> <C-o>g$
-imap <Home> <C-o>g0
-imap <Down> <C-o>gj
-imap <Up> <C-o>gk
-nmap <Down> gj
-nmap <Up> gk
-nmap <End> g$
-nmap <Home> g0
-nmap 0 g0
-nmap ^ g^
-nmap $ g$
-" Allow backspace, space, left/right keys to move across lines
-set whichwrap=b,s,<,>,[,]
+" Save using sudo
+command SudoWrite call SudoWriteFunction()
+
+" I frequently type :Q or :WQ, etc instead of :q, :wq
+command WQA :wqa
+command WqA :wqa
+command WQa :wqa
+command Wqa :wqa
+command WA :wa
+command Wa :wa
+command WQ :wq
+command Wq :wq
+command W :w
+command Wn :wn
+command WN :wn
+command Wp :wp
+command WP :wp
+command QA :qa
+command Qa :qa
+command Q :q
+
+" Make the number pad work
+map \eOX =
+imap \eOX =
+set t_KC=\eOp " 0
+set t_KD=\eOq " 1
+set t_KE=\eOr " 2
+set t_KF=\eOs " 3
+set t_KG=\eOt " 4
+set t_KH=\eOu " 5
+set t_KI=\eOv " 6
+set t_KJ=\eOw " 7
+set t_KK=\eOx " 8
+set t_KL=\eOy " 9
+
+" Toggle wordwrap
+function WrapToggle()
+       if &wrap
+               call WrapOff()
+               echo "Word wrap off"
+       else
+               call WrapOn()
+               echo "Word wrap on"
+       endif
+endfunction
+
+" Turn word wrap off, reset arrows, home, end, etc to default bindings
+function WrapOff()
+       setlocal nowrap
+       " Go up and down by physical linebreaks when not wordwrapped
+       iunmap <buffer> <End>
+       iunmap <buffer> <Home>
+       iunmap <buffer> <Down>
+       iunmap <buffer> <Up>
+       nunmap <buffer> <Down>
+       nunmap <buffer> <Up>
+       nunmap <buffer> <End>
+       nunmap <buffer> <Home>
+       nunmap <buffer> 0
+       nunmap <buffer> ^
+       nunmap <buffer> $
+       vunmap <buffer> <Down>
+       vunmap <buffer> <Up>
+       vunmap <buffer> <End>
+       vunmap <buffer> <Home>
+       vunmap <buffer> 0
+       vunmap <buffer> ^
+       vunmap <buffer> $
+       " Allow only backspace & space
+       set whichwrap=b,s
+endfunction
+
+" Turn word wrapping on and bind arrows, home, end, etc to display lines
+function WrapOn()
+       setlocal wrap
+       " Go up and down by display lines, not linebreaks when wordwrapped
+       imap <buffer> <End> <C-o>g$
+       imap <buffer> <Home> <C-o>g0
+       imap <buffer> <Down> <C-o>gj
+       imap <buffer> <Up> <C-o>gk
+       nmap <buffer> <Down> gj
+       nmap <buffer> <Up> gk
+       nmap <buffer> <End> g$
+       nmap <buffer> <Home> g0
+       nmap <buffer> 0 g0
+       nmap <buffer> ^ g^
+       nmap <buffer> $ g$
+       vmap <buffer> <Down> gj
+       vmap <buffer> <Up> gk
+       vmap <buffer> <End> g$
+       vmap <buffer> <Home> g0
+       vmap <buffer> 0 g0
+       vmap <buffer> ^ g^
+       vmap <buffer> $ g$
+       " Allow backspace, space, left/right keys to move across lines
+       set whichwrap=b,s,<,>,[,]
+endfunction
+
+
+" Toggle show invisible characters
+function InvShow()
+       if &list
+               echo  "Invisible characters off"
+               set nolist
+       else
+               echo "Invisible characters on"
+               set listchars=tab:.\ ,trail:!
+               set list
+       endif
+endfunction
+
 
 " Spell checking mode toggle
-function s:spell()
+function ToggleSpelling()
        if !exists("s:spell_check") || s:spell_check == 0
                echo  "Spell check on"
                let s:spell_check = 1
@@ -69,6 +157,11 @@ function s:spell()
                setlocal spell spelllang=
        endif
 endfunction
-map <F8> :call <SID>spell()<CR>
-imap <F8> <C-o>:call <SID>spell()<CR>
+
+
+" Save using sudo
+function SudoWriteFunction()
+       :w !sudo tee %
+       :e!
+endfunction