Paste indent when pasting in VIM

So, I'm still pretty new to VIM, but so far I have succeeded. I am using python.vim in my syntax folder. But whenever I insert python code from outside into VIM, the indentation is different. The VIM syntax makes an 8 char wide tab, but the inserted text is 4 spaces. You can see it in this picture:

Vim pasted code

Is the syntax file incorrect? Or do I need to configure some settings?

+7
python vim clipboard
source share
3 answers

You can simply set vim to convert spaces to tabs. Try to install:

tabstop=4 shiftwidth=4 expandtab 

in your .vimrc. Also, just before inserting

 :set paste 

Then paste, paste, then

 :set nopaste 

Here is a good record in insert mode .

+6
source share

Try setting tabstop and shiftwidth to 4 .

 set tabstop=4 set shiftwidth=4 
+1
source share

Sometimes when pasting vim you can visually select the copied code and click

 = 

which will reformat the code to your settings.

+1
source share

All Articles