I like to code with 4 spaces as a tab.

I added this to after/ftplugin/sass.vim:

echom "before sass file settings"
set shiftwidth=4 " <---- Problem setting, keeps changing back to 2 automatically
set softtabstop=4
set expandtab
echom "after sass file settings"

This is the standard way I set preferences for filetypes and it usually works.

I open a .sass file, and type :messages I see the echom messages printed, but then if I try: echom &shiftwidth it prints 2.

After some searching I tried: verbose set shiftwidth? and it prints:

        Last set from /tmp/.mount_nvimSdR08f/usr/share/nvim/runtime/indent/scss.vim

changing /tmp/.mount_nvimSdR08f/usr/share/nvim/runtime/indent/scss.vim does not seem like a permanent fix but I tried opening it anyways and changed this line from:

setlocal autoindent sw=2 et


setlocal autoindent sw=4 et

But the shift width still stays at 2.

I tried starting it with nvim -u NORC, but then it doesnt use my after/ftplugin at all.

How do I prevent it from revertinf shiftwidth back to 2 (make it stay at 4)?

1 Answer 1


Add your setting to after/indent/sass.vim instead of the ftplugin directory.

Vim loads multiple scripts for each filetype, the plug-ins (from ftplugin), the indentation scripts (from indent) and the syntax highlighting rules (from syntax) and it does so in a specific order. This also depends on whether you have :filetype plugin indent on (and also :syntax enable) to activate all these script types.

It seems you found that the indent scripts are loaded after the ftplugin ones, which is natural. So it turns out that the indent/sass.vim script (which will load indent/scss.vim, where your current setting is coming from) is being loaded later than the after/ftplugin/sass.vim, since all the ftplugin scripts will be processed first, and then Vim will start with the indent ones.

So simply move your setting to an indent script instead. You should still use one inside an after/ directory to make sure it loads last (among the other indent scripts.)

  • 1
    There always another layer to learn with VIM, thanks so much for that detailed answer, a great help! Sep 30, 2020 at 20:15
  • 1
    I would call this a bug. I think the indent script should not set the shiftwidth setting. That should be set (if at all) as a filetype plugin. Oct 1, 2020 at 6:09
  • 1
    I’m inclined to agree with @ChristianBrabandt; indent scripts should use &l:shiftwidth where possible without setting it.
    – D. Ben Knoble
    Oct 1, 2020 at 12:04

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.