I have the following in my .vimrc:

set expandtab "Use soft tabs (spaces)
set shiftwidth=2 "Set tab width = 2
set softtabstop=2 "Set tab width = 2
set autoindent "Set indent of previous line

Now if I open another file which contains soft tabs of width 4 spaces, how can I make Vim to automatically set my tab also to 4 spaces, depending on the file. Currently, if I'm on a line which is indented 4 spaces and I press o in normal mode, the cursor jumps to next line, but only 2 spaces from left.
I also tried using set smartindent, but doesn't work.

  • My guess is that you should have a look at filetype plugins. Mar 19, 2018 at 11:50
  • % vim: softtabstop=4 shiftwidth=4 as last line in that file if it's only one particular file and not a general rule.
    – Skillmon
    Mar 19, 2018 at 12:58


Browse other questions tagged or ask your own question.