How to preserve tabs in Vim when you paste something? [duplicate]
Matthew Barrera
When I paste any code into Vim, I the following happens.
How could I tell Vim not to screw up my tabs?
01 Answer
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 pasteIt'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:
"+pto 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
endifBTW, 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 :)
1