My ~/.vimrc contains the following:

set noet
set ts=8
set sw=8

When I open vim without arguments:

:set et? -> noexpandtab


:set sw? -> shiftwidth=8

but when I open a file: :e somefile.py

:set et? -> expandtab


:set sw? -> shiftwidth=4

but editing ~/.vimrc yields the same results like when I opened vim without arguments

Why does this happen and how to fix it?


1 Answer 1


Vim may override your global settings with filetype-specific settings through filetype plugins. (There are also indent plugins that can affect this behavior.)

In the specific case of Python shift width and tab expansion, this behavior is enabled by script $VIMRUNTIME/ftplugin/python.vim which ships with Vim.

Note that, in the specific case of the Python options you mentioned, you can override them by setting a global variable to tell Vim you'd like it not to set them. You can do so by adding this variable setting to your vimrc:

let g:python_recommended_style = 0

This behavior (and the variable to override it) is documented under :help ft-python-plugin.

  • How about :filetype off to disable filetype detection, filetype plugins and indent plugins? Apr 19, 2021 at 5:58
  • @ChristianBrabandt Yes, that works, of course, but it has many other side effects, such as disabling syntax highlighting... Perhaps disabling only ftplugins (and perhaps indent), leaving detection enabled, is a more targeted solution. But it might end up disabling some parts that you like to have.
    – filbranden
    Apr 19, 2021 at 11:58
  • 1
    This solves the problem for Python, thanks! But how to I disable all filetype plugins without disabling filetype detection? Putting filetype indent plugin off into my vimrc didn't disable everything: tw is still set to 78 in plain text files even though its set to 0 in my vimrc
    – lsmw
    Apr 20, 2021 at 21:24
  • 1
    @lsmw Can you check what :verbose set tw? says while you're editing a plain text file? That should tell you about where this setting is coming from...
    – filbranden
    Apr 20, 2021 at 23:09
  • 1
    @filbranden Last set from /etc/vim/vimrc line 160 - apparently my distro is overwriting my local vimrc, thanks for your help!
    – lsmw
    Apr 22, 2021 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.