Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bad indentation when pasting into VIM

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?

like image 788
user3056783 Avatar asked Apr 09 '14 15:04

user3056783


People also ask

How do I paste properly in Vim?

That makes the default paste buffer map to X's clipboard. So, if I mark a bit of text in a terminal, I can simply press p to paste it in vim. Similarly, I can yank things in vim (e.g. YY to yank the current line into the buffer) and middle click in any window to paste it.

How do I turn off auto indent in Vim?

How to Turn Off Vim Auto Indent. You can also temporarily turn off automatic indenting by typing :set paste in command mode. (:unset paste to turn it back on again.) This is useful — as you might guess from the command name — if you're pasting in chunks of text or code to avoid getting annoying extraneous indents.

How do I turn on auto indent in Vim?

How to Turn On Auto Indent in Vim. To automatically indent when editing a file in Vim, enable the auto indenting feature using the :set autoindent flag in command mode: Press Enter, and this will auto-indent the file you are currently editing.

Can you paste into Vim?

You can use a movement command or up, down, right, and left arrow keys. Press y to copy, or d to cut the selection. Move the cursor to the location where you want to paste the contents. Press P to paste the contents before the cursor, or p to paste it after the cursor.


1 Answers

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.

like image 172
kojiro Avatar answered Oct 05 '22 16:10

kojiro