Vim: Pasting text as is in Vim in Paste Mode

Posted on In QA

Pasting code from another application to Vim is a nightmare. The autoindent features of Vim drive you crazy. How to make it easier to use?

Pasting code from another application to Vim is a nightmare. The autoindent features of Vim will drive you crazy. What help you out is the “paste mode”.

To paste code as is:

:set paste

Past code to vim

:set nopaste

But typing so many characters is not convenient enough. We can turn auto indenting for pastes on and off with pastetoggle:

Add to ~/.vimrc:

set pastetoggle=<F2>

The to paste code (in insert mode, of course):

Press F2 (toggles the ‘paste’ option on).
Paste code.
Press F2 (toggles the ‘paste’ option off).

Leave a Reply

Your email address will not be published. Required fields are marked *