8

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?

andypea
  • 1,343
  • 11
  • 22

2 Answers2

13

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.

fphilipe
  • 9,739
  • 1
  • 40
  • 52
  • 2
    Thanks! For anyone else using NeoVim the default location of the `after/` directory is: `~/.config/nvim/after/`. – andypea Jun 07 '19 at 00:48
  • @andypea, thanks, to be specific, the default location is: `~/.config/nvim/after/plugin`. – Gang Liang Jul 01 '22 at 21:20
4

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.

shucks
  • 41
  • 1
  • 2