" Function key mappings map :call ToggleSpelling() imap :call ToggleSpelling() map :call InvShow() imap :call InvShow() map :call WrapToggle() imap :call WrapToggle() map :call PasteToggle() imap :call PasteToggle() " Unhighlight search results and redraw the screen nmap :nohlsearch:redraw! " Map Y to be consistent with D, C, etc nmap Y y$ " CTRL-n and CTRL-p to go forwards and backwards through files nmap :next nmap :prev " CTRL-J/K to move up and down, collapsing open windows map j_ map k_ " Press CTRL-z after pasting something to fix up formatting imap u:set paste.:set nopastei " Tab to switch between split windows nmap nmap [Z W " Q to reformat paragraph. I never use ex mode anyway (default binding for Q) nmap Q gwip " 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 OX = imap OX = set t_KC=Op " 0 set t_KD=Oq " 1 set t_KE=Or " 2 set t_KF=Os " 3 set t_KG=Ot " 4 set t_KH=Ou " 5 set t_KI=Ov " 6 set t_KJ=Ow " 7 set t_KK=Ox " 8 set t_KL=Oy " 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 iunmap iunmap iunmap nunmap nunmap nunmap nunmap nunmap 0 nunmap ^ nunmap $ vunmap vunmap vunmap vunmap vunmap 0 vunmap ^ vunmap $ " 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 g$ imap g0 imap gj imap gk nmap gj nmap gk nmap g$ nmap g0 nmap 0 g0 nmap ^ g^ nmap $ g$ vmap gj vmap gk vmap g$ vmap g0 vmap 0 g0 vmap ^ g^ vmap $ 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 ToggleSpelling() if !exists("s:spell_check") || s:spell_check == 0 echo "Spell check on" let s:spell_check = 1 setlocal spell spelllang=en_au else echo "Spell check off" let s:spell_check = 0 setlocal spell spelllang= endif endfunction " Save using sudo function SudoWriteFunction() :w !sudo tee % :e! endfunction " Toggle paste mode function PasteToggle() if &paste set nopaste echo "Paste mode disabled" else set paste echo "Paste mode enabled" endif endfunction