This is puzzling. I’ll share what I found so far but I also don’t know what causes this.
I believe I know why it works with vim-plug
, the explanation is at the bottom of the post
When using the packages
option the highlight group is cleared at some point. Running :hi trai
followed by trying to autocomplete the highlight group name yields no results. Dumping some highlight group related commands into a buffer with :put=execute('verbose highlight')
shows, among many other things:
jsonString xxx links to GruvboxFg1
Last set from /nix/store/89m1lc0dy0ayxlbz35y53qyqxy3vyizp-vimplugin-gruvbox-2020-07-03/share/vim-plugins/gruvbox/colors/gruvbox.vim line 1400
trailingWhitespace xxx cleared
Ignore xxx ctermfg=0 guifg=bg
Last set from /nix/store/j00jh9z55wlcldb1qy8xv66j30lv4qy0-neovim-unwrapped-0.5.0/share/nvim/runtime/syntax/syncolor.vim line 42
I vaguely remembered that color schemes interfere with custom highlight groups, and indeed this gist explains it in a bit more detail. Additionally, the Gruvbox source, like most color scheme plugins, clears the existing highlight groups.
Of course none of this explains the issue since the :highlight
command happens after the colorscheme
command. On the other hand, the plugin file is sourced after the init.vim
in both Neovim configurations.
Bad
1: /nix/store/avfqw388zpaw3kxrp4al5iwmwyc4njqk-init.vim
2: /nix/store/89m1lc0dy0ayxlbz35y53qyqxy3vyizp-vimplugin-gruvbox-2020-07-03/share/vim-plugins/gruvbox/colors/gruvbox.vim
...
Good
1: /nix/store/752v4pldlg9syn9m74h6jnrkbi9iqcmf-init.vim
2: /nix/store/99k9mgg1x3hvwavqgmby9jqsa5w7b4zr-vimplugin-vim-plug-2021-04-30/share/vim-plugins/vim-plug/plug.vim
3: /nix/store/j00jh9z55wlcldb1qy8xv66j30lv4qy0-neovim-unwrapped-0.5.0/share/nvim/runtime/filetype.vim
4: /nix/store/j00jh9z55wlcldb1qy8xv66j30lv4qy0-neovim-unwrapped-0.5.0/share/nvim/runtime/ftplugin.vim
5: /nix/store/j00jh9z55wlcldb1qy8xv66j30lv4qy0-neovim-unwrapped-0.5.0/share/nvim/runtime/indent.vim
6: /nix/store/j00jh9z55wlcldb1qy8xv66j30lv4qy0-neovim-unwrapped-0.5.0/share/nvim/runtime/syntax/syntax.vim
7: /nix/store/j00jh9z55wlcldb1qy8xv66j30lv4qy0-neovim-unwrapped-0.5.0/share/nvim/runtime/syntax/synload.vim
8: /nix/store/j00jh9z55wlcldb1qy8xv66j30lv4qy0-neovim-unwrapped-0.5.0/share/nvim/runtime/syntax/syncolor.vim
9: /nix/store/89m1lc0dy0ayxlbz35y53qyqxy3vyizp-vimplugin-gruvbox-2020-07-03/share/vim-plugins/gruvbox/colors/gruvbox.vim
...
The only thing I find interesting is that there are some syntax related runtime files that are sourced before Gruvbox loads in the working configuration.
Other than that, the next step would probably be to look at what vim-plug
actually does. Clearly the order in which files are sourced seems to matter here.
Just when I was about to give up and post this, I took another look at this PR . So I added:
colorscheme gruvbox
syntax enable
highlight trailingWhitespace ctermbg=Red guibg=red
and what do you know, :hi trai
now works.
Here’s what help says
The `:syntax enable` command will keep most of your current color settings.
This allows using `:highlight` commands to set your preferred colors before or
after using this command. If you want Vim to overrule your settings with the
defaults, use: >
Not sure how this now relates to the following highlight group settings and the interactions with the color scheme but I think this at least seems to explain why it works with vim-plug
since it seems to include additional syntax enable
calls. I could imagine that if packages
would source the plugins after loading the syntax runtime files it might also work. I don’t know if they automatically enable syntax in the same way that the command does it, but it’d be worth a shot.