Vim tab length is different for .py files

In my ~/.vimrc I set a tab for me 2 spaces long

 set shiftwidth=2 set tabstop=2 

However, when I open the .py file, the tabs are 4 spaces long. I have no specific configuration for python files. ~/.vim/after empty and py search does not call suspicious strings.

Have you ever experienced this? How to solve this behavior?

+7
python vim indentation
source share
2 answers

Defined in a general file plugin file of a Python type file ( $VIMRUNTIME/ftplugin/python.vim ):

 " As suggested by PEP8. setlocal expandtab shiftwidth=4 softtabstop=4 tabstop=8 

This should be consistent with PEP 8 .


@Carpetsmoker adds:

The vim-dev @ list has a discussion of this .

You can use reset using this in your ~/.vimrc ; eg:

 aug python " ftype/python.vim overwrites this au FileType python setlocal ts=4 sts=4 sw=4 noexpandtab aug end 

Or by adding configuration settings to $HOME/.vim/after .

+9
source share

You probably have some kind of plugin installed to make python easier to edit, and this plugin has reinstalled some vim options.

You can find out:

  • open one py file, make sure tabstop / shiftwidth 4
  • then run the command:: :verbose set ts and :verbose set sw

You can see where the settings were last set.

0
source share

All Articles