1

Problem

I'm finally getting around to upgrading from Vim 7.4 to Vim 8.1, but my global custom highlight colors have stopped working.

I am aware similar questions (such as this one) have been asked, but these all seem to be related to the closed Issue #542, and none of the solutions there seem to work for me.

Version Info

8.1 from the jonathonf/vim ppa repository on Ubuntu 18.04.

VIM - Vi IMproved 8.1 (2018 May 18, compiled Aug 22 2018 11:42:48)
Included patches: 1-346
Modified by [email protected]

Full --version text (Pastebin link) I also tried Vim 8.0 from Ubuntu 18.04's vim package

Minimum steps to reproduce

Create the following .vimrc file:

echo "Read the correct vimrc"
hi Comment ctermfg=green cterm=none

Edit any file with comments; "Read the correct vimrc" is displayed, but the comment color is not green.

Additionally, sometimes I can see the color change a few milliseconds after the file is opened, suggesting something may indeed be overriding my settings.

Running :hi Comment ... from within vim works as expected.

Running vim with/without -u .vimrc does not make a difference.

Other things I've tried

I've tried using the autocmd suggestion from the above linked answer, to no avail. In short, that looks something like this:

augroup customhighlight
        autocmd!
        autocmd ColorScheme * hi Comment ctermfg=green
augroup end

I then went down the rabbit hole of vimrc defaults:

   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/share/vim"

Unfortunately, unless I missed something, there doesn't appear to be anything in the default/Debian vim defaults that would override a user .vimrc, and, indeed, that would be silly.


I have not gone down the route of implementing custom color schemes, which was another suggestion. Reason being, I work with a lot of different filetypes on a regular basis, and there has always been a way to globally customize colors, so I'm hoping there's a solution.


:verbose hi Comment reports:

Comment        xxx term=bold ctermfg=14 guifg=#80a0ff
        Last set from /usr/share/vim/vim81/syntax/syncolor.vim

:colorscheme reports default

Summary

What is the best practice to set global syntax highlight color preferences in Vim 8.x?

6
  • Could a colorscheme be overriding it? What color is Comment set to? What about verbose hi Comment ?
    – D. Ben Knoble
    Sep 4, 2018 at 13:39
  • From my reading of the Vim help, either your direct setting of the Comment highlight, if no colorscheme was set, or your ColorScheme autocommand, if a colorscheme was set, should have worked. If we find it's not working, we can submit a bug report. Before doing that, though, try executing this command: :verbose hi Comment. That should tell you where the Comment highlighting was last set. You might also execute :au ColorScheme to see if there are any other ColorScheme autocommands that might be overriding yours.
    – garyjohn
    Sep 4, 2018 at 17:18
  • @D.BenKnoble and @garyjohn I've edited the question with that information. Looks otherwise normal to me, except something is (re)setting the highlight colors after .vimrc. There is no autocommand reported by :au ColorScheme. Sep 5, 2018 at 4:48
  • It looks like syntax on could be the culprit. Is your custom highlight before or after that line in your vimrc ?
    – D. Ben Knoble
    Sep 5, 2018 at 13:11
  • Since the Comment highlight was last set in syncolor.vim, I looked at that file and also read ":help syncolor". There it suggests creating a file ~/.vim/after/syntax/syncolor.vim and uses as an example setting the Comment highlight. Try that and see what happens.
    – garyjohn
    Sep 5, 2018 at 13:48

1 Answer 1

3

I don't know what changed between Vim 7.4 and 8.1 that caused this change in behavior, but the output of :verbose hi Comment that you posted provided a clue to a solution. :help syncolor suggests overriding the default highlighting colors by creating a file named ~/.vim/after/syntax/syncolor.vim (~\vimfiles\after\syntax\syncolor.vim on Windows) and putting in that file highlight commands like the following.

if &background == "light"
    highlight Comment ctermfg=darkgreen guifg=darkgreen
else
    highlight Comment ctermfg=green guifg=green
endif

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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