When I paste any code into Vim, I the following happens.
How could I tell Vim not to screw up my tabs?
Use paste
mode, which is a special mode informing vim that you're going to paste text instead of typing it.
Just type in:
:set paste
It's useful to have a mapping like:
:set pastetoggle=<F2>
to quickly switch between paste and regular mode.
Also you might want to consider pasting from clipboard using just p, if your vim supports *
and/or +
registers. In that case use:
"+p
to paste from clipboard, it'll keep indentation.
Note: it's sometimes useful to have this in your vimrc:
" better yank to clipboard
if has('clipboard')
if has('unnamedplus') " When possible use + register for copy-paste
set clipboard=unnamed,unnamedplus
else " On mac and Windows, use * register for copy-paste
set clipboard=unnamed
endif
endif
BTW, I just yanked it from my vimrc using y, and pasted it here with CTRLv, so it saves you some work ;)
I hope it helps :)