exouva
Last Updated: February 25, 2016
·
694
· marcelocajueiro

Paste code on VIM without auto-identation

vim

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

1879

Thank you so much!

over 1 year ago ·
1880

I similarly bind this to F2:

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

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

over 1 year ago ·