Search code examples
vimftplugin

vim doesn't source local ftplugin in project dir


I have set secure exrc at first line of my .vimrc in home directory and then enabled ftplugins. Now I want to overwrite some of them in some of my projects. But vim seems to source only .vimrc and not .vim/after/ftplugin/c.vim in project directory. Global configs were sourced correctly.

Here is output of :scriptnames. Lines 10, 14 and 27 are global .vimrc, local .vimrc and global ftplugin respectively:

  1: /usr/share/vim/vimrc
  2: /usr/share/vim/vim82/debian.vim
  3: /usr/share/vim/vim82/syntax/syntax.vim
  4: /usr/share/vim/vim82/syntax/synload.vim
  5: /usr/share/vim/vim82/syntax/syncolor.vim
  6: /usr/share/vim/vim82/colors/lists/default.vim
  7: /usr/share/vim/vim82/filetype.vim
  8: /usr/share/vim/vim82/autoload/dist/ft.vim
  9: /usr/share/vim/vim82/syntax/c.vim
*10: ~/.vimrc
 11: /usr/share/vim/vim82/ftplugin.vim
 12: /usr/share/vim/vim82/colors/industry.vim
 13: /usr/share/vim/vim82/keymap/russian-jcukenwin.vim
*14: /home/Common/Прога/Свое/tests/vimtest/.vimrc
 15: /usr/share/vim/vim82/plugin/getscriptPlugin.vim
 16: /usr/share/vim/vim82/plugin/gzip.vim
 17: /usr/share/vim/vim82/plugin/logiPat.vim
 18: /usr/share/vim/vim82/plugin/manpager.vim
 19: /usr/share/vim/vim82/plugin/matchparen.vim
 20: /usr/share/vim/vim82/plugin/netrwPlugin.vim
 21: /usr/share/vim/vim82/plugin/rrhelper.vim
 22: /usr/share/vim/vim82/plugin/spellfile.vim
 23: /usr/share/vim/vim82/plugin/tarPlugin.vim
 24: /usr/share/vim/vim82/plugin/tohtml.vim
 25: /usr/share/vim/vim82/plugin/vimballPlugin.vim
 26: /usr/share/vim/vim82/plugin/zipPlugin.vim
*27: ~/.vim/ftplugin/c.vim
 28: /usr/share/vim/vim82/ftplugin/c.vim

I've already tried to remove secure or global configs, but none worked.


Solution

  • No, it doesn't work like this. As :h 'exrc' says:

    Enables the reading of .vimrc, .exrc and .gvimrc in the current directory.

    Nothing is said about ftplugin or such.

    In fact, ftplugin-related things are sourced by standard ftplugin.vim script (#11 in the list above). The code simply invokes :h :runtime command in order to do this. As :h :runtime looks through :h 'runtimepath' directory list only, it does not respect any other stuff like :h 'exrc'.

    In principle you might change :h 'runtimepath' inside your local .exrc to match but it's just better to follow the advice given at :h 'exrc'

    Instead, define an autocommand in your .vimrc to set options for a matching directory.

    For ftplugin this means to change autocommand in the global config to make it depend on the current project directory.