Monday, October 14, 2013

Vim paste tricks

Vim is cool! But sometimes can be annoying - for example you edit your file etc. and have a short snippet of code you want to insert into it, so copy and paste BUT ... vim has the indent on. Now there are different types of indent and you can try to turned them off - see Indenting source code. A neat trick is the :paste option however there are cases where you want to turn off indented for different reasons. You can use something like this into your .vimrc
function! IndentPasteOff()
  set noai nocin nosi inde=

function! IndentPasteOn()
  set ai cin si

nmap _0  :call IndentPasteOff() 
nmap _1  :call IndentPasteOn() 
" paste on/off
set pastetoggle=
Now you don't want any indent type _0 and to indent again _1. Happy viming!