I am using vim 8.0.1763 on CentOS 8.1. Here is my ~/.vimrc

" Cool vim plugins : http://vimawesome.com/plugin/fugitive-vim
set number
filetype plugin on  " https://stackoverflow.com/questions/19754849/vim-syntax-highlighting-does-not-work
syntax on
" Stop annoying line wrapping when pasting
set paste
" Stop annoying line wrapping
set formatoptions-=tc
set ruler
set showmatch
set expandtab
set tabstop=4
set softtabstop=0

If I open a *.py file, and type :set softtabstop it returns 4. If I open another *.txt file, the same command returns 0. Clearly this is a python file specific behavior. The only place I can find this being set is in /usr/share/vim/vim80/ftplugin/python.vim

My intuition says that .vimrc should be loaded last.


  1. How do I get my settings in my .vimrc file to persist when opening *.py files?
  2. What is the order of operation when loading vim configuration files?

Note :

This question was incorrectly marked as a duplicate question. The accepted answer of adding

augroup python
    autocmd FileType python setlocal noet ts=4
augroup end

to my ~/.vimrc does not solve the Question 1 that I pose above. Also the previously previously asked question does not address my Question 2.

My question is unique in its own right. The accepted answer of my question is unique and not given in the previously asked question. My question should not be closed.

  • 1
    Re: your edit; I'm not sure why the accepted answer doesn't work for you at a glance; it's possible that the answer should be corrected or that a new answer should be given, but the question is still the same. The reason to mark questions as duplicates is so that people searching "python wrong tabstop" in a search engine will end up with one question which (hopefully) provides them with all possible solutions, rather than having that spread out over 2, 3, or more questions. It's to improve the long-term usefulness of the site. – Martin Tournoij Jan 29 at 3:50
  • 1
    As for your second "what is the order of operation"-question, a question should really contain just one question rather than two, for the same reasons as mentioned in the previous comment. There are already some questions touching on this (1, 2, 3), but they don't fit that question exactly, and unless I missed a question that would make for a good new question. – Martin Tournoij Jan 29 at 3:52
  • 1
    The reason the accepted answer doesn't work for you btw is probably because the example only overrides tabstop=4, and not softtabstop=0 as you want; this is just an example and should be adjusted according to personal preference (it won't work for people who want a tabstop of 2 either). I'll add a line to clarify that a bit. – Martin Tournoij Jan 29 at 3:58
  • Thank you for your clarification. I understand that you should only ask 1 question, however my 2 questions are tightly coupled and understanding #2 is important to understanding #1. Also, I'd like to point out that after searching specific strings that ended up in my question, I did not come across the question you mentioned. I had distilled the issue more specifically into my vimrc settings being clobbered by something else loaded after my vimrc. The other question mentioned is much more vague and not posed as clearly – irritable_phd_syndrom Jan 29 at 12:11
  • Perhaps you may view them as the same question, but someone searching for why their vimrc files' settings are getting clobbered and wondering what is loaded afterwards, will not find the information in a question titled "Vim doesn't use the correct indentation in Python files". – irritable_phd_syndrom Jan 29 at 12:14

There is such a thing in vim called filetype plugin aka ftplugin. It is loaded for a filetype after it was read by vim thus overriding your .vimrc settings.

for a python check :e $VIMRUNTIME/ftplugin/python.vim (line 117):

if !exists("g:python_recommended_style") || g:python_recommended_style != 0
    " As suggested by PEP8.
    setlocal expandtab tabstop=4 softtabstop=4 shiftwidth=4

You have at least 3 options here:

  1. make the if statement false by setting let g:python_recommended_style == 0
  2. override back settings in ~/.vim/after/ftplugin/python.vim -- create the file and add setlocal whatever there
  3. override back settings in your vimrc using autocommands, for example:
augroup my_python_settings | au!
    au Filetype python setlocal softtabstop=1024
augroup END

You can check actual order of loaded scripts with :scriptnames.

In general see :h VIMINIT.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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