-
Notifications
You must be signed in to change notification settings - Fork 142
Description
When this plugin is installed as a Vim8 plugin, it is not loaded until after the vimrc has been processed. This means that hooks cannot be installed in vimrc as editorconfig#AddNewHook is not yet defined. If you try the example in the plugin help,
call editorconfig#AddNewHook(function('FiletypeHook'))
then running vim gives you an error
Error detected while processing VIMINIT..script ~/.vimrc:
line 262:
E117: Unknown function: editorconfig#AddNewHook
One option to solve this is to use an autocommand on the VimEnter event which fires when startup is complete:
autocmd VimEnter * call editorconfig#AddNewHook(function('FiletypeHook'))
However, this is run after the initial buffers are loaded, so if you run vim myfile.m then the hook is not called on myfile.m, but it will be called if you subsequently load a new buffer (:e otherfile.m or equivalent).
As per https://stackoverflow.com/questions/56454847/ the suggested method for running commands after plugins are loaded is to create a file in ~/.vim/after/plugin with the code to run, so a file ~/.vim/after/plugin/editorconfig.vim with the contents call editorconfig#AddNewHook(function('FiletypeHook')) works.