25

I'm trying to override the highlight set in a plugin. The plugin does this:

highlight! link WordUnderTheCursor Underlined   

Firstly, I'm not aware that ! added to highlight does anything. But that's irrelevant.

Doing stuff like this in the vimrc

highlight clear WordUnderTheCursor                             
highlight WordUnderTheCursor cterm=bold ctermfg=254 ctermbg=160

Does not appear to affect the behavior.

Only when I directly modify the Underlined style (which feels wrong) in the vimrc, does the change apply.

Is this proof that the plugin is being run after the vimrc runs?

How might I unlink the style? I can't really tell if this is just the plugin doing something creative and unsupported, or if this is normal Vim behavior.

Dave Powers
  • 2,051
  • 2
  • 30
  • 34
Steven Lu
  • 41,389
  • 58
  • 210
  • 364

2 Answers2

42

Yes. vimrc is loaded before plugins.

If you look at :h initialization you will find that step 3 is load vimrc and step 4 is load plugins.

You can also see that vimrc is loaded before plugins by looking at the output of :scriptnames. scriptnames lists all sourced scripts in the order they were sourced and vimrc is the first thing sourced. (Take a look at :h :scriptnames).


To fix the highlighting you just need to run the highlight commands after the plugin gets sourced. To do this you put files in the after directory of your .vim directory. (Take a look at :h after-directory)

So create the file .vim/after/plugin/hicursorwords.vim with the following contents

highlight clear WordUnderTheCursor                             
highlight WordUnderTheCursor cterm=bold ctermfg=254 ctermbg=160

This will cause the plugin to be sourced before you change the settings of the plugin.

(This of course assumes you don't want to edit the plugin)

FDinoff
  • 30,689
  • 5
  • 75
  • 96
  • 2
    Awesome, thanks. I already have a few `after` scripts that override syntax settings so this fits nicely into that whole scheme. – Steven Lu Jul 17 '13 at 00:16
  • Be aware that the `_gvimrc` (for graphical purpose) is read _after_ the plugins. You therefore have to enter the commands to be token in consideration in a plugin in a _vimrc and not _gvimrc. – Olivier Faucheux Mar 24 '17 at 09:31
12

Besides scriptnames, to see what order vim runs things in on startup, you can also use:

vim --startuptime <file>

so it will log all the tasks it does in order, and how much time each one takes.

Cometsong
  • 568
  • 9
  • 21