Last Updated: February 25, 2016
·
886
· marcelocajueiro

Paste code on VIM without auto-identation

If we try to paste some code on vim it will auto-indent the code making a mess.

We can avoid that with the vim paste mode.

:set paste will start the paste mode and :set nopaste will stop it.

But to make more easy I did a shortcut to toggle the paste mode:

nnoremap <leader>p :set invpaste paste?<CR>

With this when we press <leader>p the paste mode will start so we can paste whatever we want and then we stop the paste mode with <leader>p again.

I hope you guys enjoy the tip!

3 Responses
Add your response

Thank you so much!

over 1 year ago ·

I similarly bind this to F2:

nnoremap <F2> :set invpaste paste?<CR>
set pastetoggle=<F2>
set showmode
over 1 year ago ·

This can be achieved automatically: https://coderwall.com/p/if9mda

over 1 year ago ·