pythonvim

Use Vim Retab to solve TabError: inconsistent use of tabs and spaces in indentation?


Apologize for the newbie question, but I have read the manual, this question, and tried several times without results I expected.

So I was using vim to edit a file (attached). But when running, I got the TabError: inconsistent use of tabs and spaces in indentation error.

Here is what I have tried:

My questions are:


Solution

  • Just type :help retab in Vim and read. I think I can't explain it better than the help. Maybe you are missing the optional range part; use % prefix to apply to the whole file. Also useful is :set list to show you every chars; this will show you the tabs and line ends (disable with :set nolist) and :set <name> with no value to see the current value, ex : set tabstop or followed by some value to set.

    By showing all chars, enabling and disabling expansion of tabs into spaces with :set expandtab and :set noexpandtab, setting tabstop and by using for ex. :retab! 4 you can play your way around and switch from tabs only and spaces only, and change the tab column width.

    This link, vim settings for python might be useful also