Question

This is not a very simple question.

I found that the "shiftwidth" for python files are set to 4, while I have these at the bottom of my .vimrc:

set tabstop=2                                                               
set shiftwidth=2                                                               
set softtabstop=2                                                              
set expandtab 

The shiftwidth are 2 for all other filetypes; but it's 4 only for python.

I want to know if it's possible to see where a variable (in my case, the shiftwidth) has been changed; if this is not possible when what are the possible locations that this variable is changed..? And is there any way go make the shiftwidth=2 universally... even for the python files? (Although it's also recommended of using 4 spaces for python, but I personally prefer 2)

Was it helpful?

Solution

:verbose set shiftwidth

tells you what's the current value and where it was defined. See :help :verbose.

Filetype plugins are sourced after the corresponding FileType event was triggered so they will override the options in your vimrc.


The dirty way to add filetype-specific settings to your config is to add something like this to your vimrc:

augroup Python
    autocmd!
    autocmd fileType python setlocal tabstop=2 shiftwidth=2 softtabstop=2 expandtab
augroup END

See :help :autocmd.


The clean way is to put your desired settings into a custom ftplugin.

The file:

~/.vim/after/ftplugin/python.vim

Its content:

setlocal tabstop=2
setlocal shiftwidth=2
setlocal softtabstop=2
setlocal expandtab

Note the use of setlocal instead of set because you don't want those settings to be applied everywhere.

OTHER TIPS

This is probably being set by the built-in ftplugin file for Python. If you

:e $VIMRUNTIME/ftplugin/python.vim

and search for shiftwidth, you’ll probably find it set there to 4.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top