I have most of the usual tab commands in ~/.vimrc:

set tabstop=4 set softtabstop=4 set shiftwidth=4 set expandtab

set breakindent set autoindent set smartindent.

There are no problems when I open a file that uses spaces over tabs; all tabs produce 4 spaces. But when I open a file someone else has written using tabs, the tabs produce a space of length 8 and stretches out the lines. I can remove this by typing :set tabstop=4 but why must I do this when that command is already loaded in ~/.vimrc? How can I make it automatically alter the tabs to length 4 upon opening the file?

  • 1
    Which filetype are you editing? Some filetypes reset tabstop. You can also use :verbose set tabstop to check where it was last set. Commented Sep 1, 2017 at 2:32
  • I'm editing a python file.
    – domoremath
    Commented Sep 1, 2017 at 3:30
  • 1
    Yup, Python is one of the filetypes that resets it. See the linked question on how to fix it. Commented Sep 1, 2017 at 3:31
  • Could you tell me what other common file types also resets tabstop or where I can look this up? Does this apply to e.g. C, C++, or Java files?
    – domoremath
    Commented Sep 1, 2017 at 3:44
  • 1
    There isn't a full list, but something like ag setlocal /usr/share/vim/vim80/{ftplugin,indent,syntax} comes reasonably close (use grep -r if you don't have ag installed). Commented Sep 1, 2017 at 4:15


Browse other questions tagged or ask your own question.