Wednesday, April 16, 2008

vim tip: don't mess up the indentation when you paste

vim does really lovely autoindenting. But what happens when you want to paste in pre-formatted text from somewhere else? All your code indents way off to the side, oh noes! Here's what to do.

:set paste
Okay, now paste.
:set nopaste

Perfect. I rated this tip "life-changing".

3 comments:

Anonymous said...

This has been one of the few annoyances vim has presented me when hacking - thanks for the tip.

Anonymous said...

At least in gentoo when vim is compiled with the vim-with-x flag it automatic prevents autoindent when pasting from the X clipboard(s)


vim-with-x
Global: Link console vim against X11 libraries to enable title and clipboard features in xterm
Local: Link console vim against X11 libraries to enable title and clipboard features in xterm
http://gentoo-portage.com/app-editors/vim/USE#ptabs

kaprasanna said...

Indeed life changing.. Thanks a lot.