Reputation: 425
I have set tabstop and shiftwidth to 2 in my vimrc, but still when I go to a new line vim uses 4-space indents. I also get this warning if I save a file that uses 2 spaces for indentation:
E111 indentation is not a multiple of four [pep8]
How can I make vim use 2 spaces for Python? It seems to be ignoring my vimrc for Python.
I am using vim 7.2.
Upvotes: 3
Views: 3866
Reputation: 81
This simply is not true. There is no mandate for whitespace in python and in fact Google's style guidelines for python recommend a shiftwidth of 2 spaces. 4 spaces is a PEP8 standard and is entirely a formatting preference. The ftplugin in vim defaults to use the PEP8 standard.
The cleanest way to override this is adding a python.vim file to the directory chain ~/after/ftplugin. Where ~ is the location of your vim configuration folder (usually .vim for unix and vimfiles for windows). You could then add your preferred configuration of formatting to this file.
The simplest example would be:
set shiftwidth=2
set tabstop=2
Upvotes: 8
Reputation: 1429
Whitespace is an integral part of the Python language, and four spaces is the mandate. You could, however, use only shifts and have your editor read a shift as only two spaces, but I would not recommend this. This could easily cause problems with mixing spaces and tabs, which can cause a giant hassle.
Upvotes: -1