Question

So I'm still pretty new to VIM but I've managed so far. I am using python.vim in my syntax folder. But whenever I paste python code from outside into VIM, the indentation is different. VIM syntax makes a tab, that is 8 char wide, but pasted text is 4 whitespaces. You can see it on this pic:

VIM pasted code

Is the syntax file wrong? Or should I adjust some settings?

Was it helpful?

Solution

You may just have vim set to convert spaces to tabs. Try setting:

tabstop=4 shiftwidth=4 expandtab

in your .vimrc. Also, before you paste, just do

:set paste

Then insert, paste, then

:set nopaste

Here is a good writeup on paste mode.

OTHER TIPS

Sometimes with vim pasting you can visually select the copied code and press

=

which will reformat the code to your settings.

Try setting tabstop and shiftwidth to 4.

set tabstop=4
set shiftwidth=4
" Correct bad indent while pasting.
nnoremap <Leader>p p=`]
nnoremap <Leader>P P=`]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top