Description
As you know, filetype-specific syntax items and colorscheme's switching don't go very well together—the emblematic discussion of the topic likely being altercation/solarized#102.
In a nutshell, the issue can be reproduced as follows (using Vim 8.1.1300):
- Create a minimal colorscheme
~/.vim/colors/test.vim
:
set background=dark
hi clear
if exists('syntax_on')
syntax reset
endif
let g:colors_name = 'test'
hi! link vimCommand ErrorMsg
hi vimOption cterm=reverse gui=reverse
-
Edit your
vimrc
; -
:colorscheme test
-
:colorscheme default
You will see that vimCommand
is still linked to ErrorMsg
and vimOption
is cleared.
I have thought hard about possible workarounds and my conclusion is that this issue has no solution—except avoiding using syntax items in colorschemes—unless some new mechanism (a new command?) is introduced in Vim to deal specifically with it. Am I right?
Note that avoiding syntax items in colorschemes is somewhat limiting, as one can realize by looking at two of the most popular colorschemes (Solarized and Gruvbox): people constantly ask to tweak the highlighting for specific filetypes.