Search code examples
neovimftplugin

How can I override configurations from the built-in ftplugins?


I would like to set commentstring for C files like so:

autocmd FileType c setlocal commentstring=//\ %s

But when I open a C file, I notice that setting has been overridden. I believe this line from /usr/share/nvim/runtime/ftplugin/c.vim is to blame:

setlocal commentstring& define& include&

Is there a way I can modify my init.vim to make my setting take precedence? If not, what's the most natural place to put such a setting? (And as a side question, is this behavior intended, or possibly a bug in Neovim?)


Solution

  • Try enabling filetype and plugin in init.vim

    filetype plugin indent on
    ...
    ...
    ...
    autocmd FileType c setlocal commentstring=//\ %s
    

    Note: The order is mandatory or else it would not work because user defined configs will be overwritten by defaults configs as when we enable filetype and plugin it tries to load defaults configs.