-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Installing hooks when using Vim8 plugin #161
Comments
|
Glad you were able to find a solution! PRs welcome with documentation updates :) . |
Another solution: for vim >= 8.1.0729 there is a
@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 |
@bcbnz As long as the current version posted for download on www.vim.org has |
Packages are loaded after vimrc is parsed, so we can't add the hook immediately. Suggest using either an autocommand or a file in an after-directory to add the hook instead. Fixes: editorconfig#161
Using |
Yes, if you want the plugin loaded at startup. If you have it as an optional plugin you want to load later, then |
Ah, okay. That is useful. But,
this is also applied to |
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.The text was updated successfully, but these errors were encountered: