2

I use vim via the console.

I have the following line in my vimrc:

highlight LineNr ctermfg=5 

It doesn't do anything, but when I type this in as a command, it correctly changes the line numbers' colors:

:highlight LineNr ctermfg=5

:verbose highlight LineNr gives:

LineNr xxx term=underline ctermfg=11 guifg=Yellow Last set from /usr/share/vim/vim74/colors/elflord.vim 

I've been looking all over for some clue about something I'm missing, but I can't see what it is.

I've also tried using highlight with various other things, like CursorLine, and I can't get it to work with those either.

This is the verbose output for LineNr:

enter image description here

Its odd that the colorscheme is the only thing changing the color-I added the highlight line after the colorscheme in the vimrc.

  • What else do you have after the highlight command in your vimrc? (Also, text please, not pictures) – muru Jan 6 '17 at 13:40
  • I had "syntax on" after the highlight command. That was my problem. Thank you! – William Sturgiss Jan 6 '17 at 13:46
  • Also see this question. I'm not 100% sure if I should mark it as a duplicate since this question is a bit more general, but it's the same root problem: Vim will reset highlights on many occasions, and the best way to fix that is to add that to your vimrc is with an autocmd. – Martin Tournoij Jan 6 '17 at 13:56
  • I see how they are somewhat similar but I think this one is different in that it can be solved by simply having the correct order of commands. – William Sturgiss Jan 6 '17 at 14:24
  • @WilliamSturgiss Yeah, it's not 100% identical. Still, using an autocommand is the "safest" way IMHO, since later additions to your vimrc might break stuff. – Martin Tournoij Jan 6 '17 at 14:40
3

If you have anything later in the .vimrc file that changes the same thing as the highlight line, the highlight line will be overridden.

In this case, my "syntax on" line was after the highlight line. Syntax on changes the Line number colors and was blowing away the highlight line changes.

This is what I had before:

highlight LineNr ctermfg=5 
syntax on

This is the correct order to allow the highlight line to override the "syntax on" line:

syntax on
highlight LineNr ctermfg=5 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.