Skip to content

Installing hooks when using Vim8 plugin #161

Open
@bcbnz

Description

@bcbnz

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions