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 jonathonf.fernyhough@york.ac.uk
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?
verbose hi Comment? – D. Ben Knoble Sep 04 '18 at 13:39:verbose hi Comment. That should tell you where the Comment highlighting was last set. You might also execute:au ColorSchemeto see if there are any other ColorScheme autocommands that might be overriding yours. – garyjohn Sep 04 '18 at 17:18:au ColorScheme. – type_outcast Sep 05 '18 at 04:48syntax oncould be the culprit. Is your custom highlight before or after that line in your vimrc ? – D. Ben Knoble Sep 05 '18 at 13:11syntax ondidn't seem to make a difference if it was before, after, or not included whatsoever. Similarly withsyntax enable.However, the
syncolor.vimapproach does work. I checked thesyncolordocumentation for 7.2 and it hasn't changed much. I'd be more willing to accept I've been doing it wrong for the past twenty-ish years if setting right in.vimrcdidn't work so well up until 8.0!Thanks @garyjohn . Although I no longer have a "one file" portable Vim configuration, at least it works. If you'd like to post this as an answer, I'd be happy to accept it.
– type_outcast Sep 05 '18 at 14:19