andypea
andypea

Reputation: 1401

In Vim, how to I set an autocommand to be run after a plugin has loaded?

One of the Vim Plugins I use has a bug, causing it to set :syntax spell notoplevel. The bug is easily mitigated if I run the command :syntax spell toplevel after opening a file. However, I'm lazy and I'd like to put the fix in my init.vim / .vimrc file, so that it's run automatically.

How can I ensure that my fix is executed after the buggy plugin code, so that my setting is not overridden by the plugin?

Upvotes: 8

Views: 4892

Answers (2)

shucks
shucks

Reputation: 51

Alternatively, you can set it as an autocommand. There are a whole slew of events you can tie autocommands to (:help events for all of them). VimEnter is an event that fires after plugins are loaded, so you could set your command to run then with a line like this right in your vimrc:

autocmd VimEnter * syntax spell toplevel

That's what I am using to apply a plugin theme that is not available until after plugins load.

Upvotes: 5

fphilipe
fphilipe

Reputation: 10056

Create a file in ~/.vim/after/plugin/ such as ~/.vim/after/plugin/fix-spell.vim containing the command you'd run without the colon:

syntax spell toplevel

The files in ~/.vim/after/plugin are sourced after your plugins have loaded, thus providing a convenient hook to change settings that might have been set by a plugin.

Upvotes: 13

Related Questions