Ubuntu – VIM “upgraded” to expandtab and tabstop=8 on Python files

kubuntupythonUbuntuvim

After reinstalling my OS from Kubuntu 12.10 to Kubuntu 14.04, VIM has changed its behaviour when editing Python files. Though before the reinstall all file types had noexpandtab and tabstop=4 set, now in Python those values are expandtab and tabstop=8, checked also via VIM behaviour and also via asking VIM set foo?.

Non-Python files retain the noexpandtab and tabstop=4 behaviour that I prefer.

The .vim direcotry and .vimrc were not touched during the reinstall. It can be seen that no files in .vimrc have been touched in months (with the exception of the irrelevant .netrwhist):

 - bruno():~$ ls -lat ~/.vim
total 68
drwxr-xr-x 85 dotancohen dotancohen 12288 Aug 25 13:00 ..
drwxr-xr-x 12 dotancohen dotancohen  4096 Aug 21 11:11 .
-rw-r--r--  1 dotancohen dotancohen   268 Aug 21 11:11 .netrwhist
drwxr-xr-x  2 dotancohen dotancohen  4096 Mar  6 18:31 plugin
drwxr-xr-x  2 dotancohen dotancohen  4096 Mar  6 18:31 doc
drwxrwxr-x  2 dotancohen dotancohen  4096 Nov 29  2013 syntax
drwxrwxr-x  2 dotancohen dotancohen  4096 Nov 29  2013 ftplugin
drwxr-xr-x  4 dotancohen dotancohen  4096 Nov 29  2013 autoload
drwxrwxr-x  5 dotancohen dotancohen  4096 May 27  2013 after
drwxr-xr-x  2 dotancohen dotancohen  4096 Nov  1  2012 spell
-rw-------  1 dotancohen dotancohen   138 Aug 14  2012 .directory
-rw-rw-r--  1 dotancohen dotancohen   190 Jul  3  2012 .VimballRecord
drwxrwxr-x  2 dotancohen dotancohen  4096 May 12  2012 colors
drwxrwxr-x  2 dotancohen dotancohen  4096 Mar 16  2012 mytags
drwxrwxr-x  2 dotancohen dotancohen  4096 Feb 14  2012 keymap

Though .vimrc has been touched since the reinstall, it was only me testing to see where the problem is.

How can I tell what is settingexpandtab and tabstop?

Side note: I'm not even sure what I should read in the built-in help for this issue. I started with ":h plugin" but that did not help other than showing me that the following plugins are loaded (possibly relevant):

                                                standard-plugin-list    
Standard plugins
pi_getscript.txt Downloading latest version of Vim scripts
pi_gzip.txt      Reading and writing compressed files
pi_netrw.txt     Reading and writing files over a network
pi_paren.txt     Highlight matching parens
pi_tar.txt       Tar file explorer
pi_vimball.txt   Create a self-installing Vim script
pi_zip.txt       Zip archive explorer

LOCAL ADDITIONS:                                local-additions
DynamicSigns.txt - Using Signs for different things
NrrwRgn.txt   A Narrow Region Plugin (similar to Emacs)
fugitive.txt  A Git wrapper so awesome, it should be illegal
indent-object.txt         Text objects based on indent levels.
taglist.txt     Plugin for browsing source code
vimwiki.txt   A Personal Wiki for Vim

Best Answer

You can check where those values were changed via

:verbose setlocal ts? et?

Likely, it's by this added line in $VIMRUNTIME/ftplugin/python.vim:

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

You can undo this via a script ~/.vim/after/ftplugin/python.vim with the following contents

setlocal noexpandtab shiftwidth=4 softtabstop=0 tabstop=4

Or, if you want to configure tabs per project, not globally, add

let g:python_recommended_style=0

to project's .vimrc. After that python plugin will not enforce PEP8 recommendations and you free to setup tabs in proect's .vimrc.

Related Question