A very common confusion for new users of Neovim is that their option settings for a particular filetype does not work in init.vim (or init.lua).

For non-indent related option

For non-indent related option, to make sure you option settings have the precedence over builtin. For filetype foo, you can create {NVIM_CONF_DIR}/after/ftplugin/foo.vim or (foo.lua) and write your setting their. For example,

setlocal expandtab
setlocal tabstop=2
setlocal shiftwidth=2
setlocal softtabstop=2

For indent related options

Someone asked a question on stack overflow about php. The issue is that setting smartindent and indentexpr in ~/.config/nvim/after/ftplugin/php.lua does not work. After opening a php file, smartindent and indentexpr are still set by the php.vim under nvim runtimepath:


This is because script under indent/ and syntax/ directory is sourced after script in ftplugin/. The source order is as follows:

" first wave

" second wave

" third wave

So in order for the user’s indent setting to take precedence, we need to put it under ~/.config/after/indent/.

Here is what works for me.

  • create the file ~/.config/nvim/after/indent/php.lua

  • add the settings there:

    vim.o.smartindent = true
    vim.o.indentexpr = ''