3

I have a file called ~/.config/nvim/after/ftplugin_after.vim, which contains set incsearch ignorecase smartcase number relativenumber autoindent shiftwidth=8 tabstop=8 softtabstop=8 expandtab showbreak=¶ notimeout. I am mainly concerned about the tabstop.

I used to set tab settings in ~/.config/nvim/init.vim, until I noticed it was being overridden in some files. The culprit was /usr/share/nvim/runtime/ftplugin/. I managed to get vim to ignore them, but I missed some of the features.

I even tried setting these values using autocmd VimEnter, but that didn't work. I expect the after/ directory is the best method.

I just want my tab settings to be applied to all files.

1 Answer 1

1

I have a file called ~/.config/nvim/after/ftplugin_after.vim

The correct path you're looking for is actually:

~/.config/nvim/ftplugin/filetype.vim

Note that ftplugin needs to be a directory, and that the *.vim file inside it must be named after the filetype of the files you would like to match.

The ftplugin scripts must always match a specific filetype, you can't really create a script in that directory to apply to all files you edit, regardless of filetype...

The culprit was /usr/share/nvim/runtime/ftplugin/

Yes, but which script inside ftplugin/? The scripts on that directory will only be loaded based on the filetype of the buffer you're currently editing.

You can use the command :set ft? to find which filetype is set to the current buffer, so you can use it in your ftplugin/ override.

which contains set incsearch ignorecase smartcase number relativenumber autoindent shiftwidth=8 tabstop=8 softtabstop=8 expandtab showbreak=¶ notimeout. I am mainly concerned about the tabstop.

Note that you should typically use setlocal instead of set in an ftplugin script. Since it's loaded for each buffer, based on the filetype, you'll want to make sure you only define buffer-local settings and mappings, so that they only affect buffers of that specific filetype and not others.

(One final subtlety of ftplugin scripts is that you might want to define a b:undo_ftplugin variable, with commands that can be used to undo its actions. This is used if you ever change filetypes of a buffer, in which case Vim will be able to undo the changes from the previous filetype before applying the ones for the next filetype.)

1
  • 2
    This works, but I was hoping to get one file to override all ftplugins, rather than a file for each filetype.
    – Not me
    Commented Aug 11, 2020 at 16:06

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.