Open bcbnz opened 3 years ago
packadd! editorconfig-vim
might be used.
Glad you were able to find a solution! PRs welcome with documentation updates :) .
Another solution: for vim >= 8.1.0729 there is a SourcePost
event which is triggered after a script is sourced. This can be used to call the AddNewHook function:
autocmd SourcePost */plugin/editorconfig.vim call editorconfig#AddNewHook(function('FiletypeHook'))
@cxw42 -- I'm happy to work on a PR. I think it would be cleanest if the help had one method that worked for both Vim8 plugins and for external plugin managers. Since the current example presumably works for external managers, I assume that either the separate file in ~/.vim/after/plugin/
or the SourcePost
event in vimrc options would work. I would prefer the SourcePost
way myself to keep everything in one file, and the commit that added it was almost 2 years ago so it should be available in most builds by now. Any objections?
@bcbnz As long as the current version posted for download on www.vim.org has SourcePost
, that's fine with me! Thanks!
Using packadd!
is simpler than SourcePost, I think.
Yes, if you want the plugin loaded at startup. If you have it as an optional plugin you want to load later, then PackAdd!
in the vimrc forces it to be loaded at startup whereas SourcePost works whenever it is loaded.
Ah, okay. That is useful. But,
then
PackAdd!
in the vimrc forces it to be loaded at startup
this is also applied to ~/.vim/after/plugin/
.
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 invimrc
aseditorconfig#AddNewHook
is not yet defined. If you try the example in the plugin help,then running vim gives you an error
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 onmyfile.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 contentscall editorconfig#AddNewHook(function('FiletypeHook'))
works.