dracula / vim

🧛🏻‍♂️ Dark theme for Vim
https://draculatheme.com/vim
MIT License
1.34k stars 455 forks source link

Cannot customize plugin specific highlight groups linked in /after files. #320

Closed adriantrunzo closed 7 months ago

adriantrunzo commented 8 months ago

What happened

I would like to overwrite the highlight group for GitGutterDelete that is linked in /after/plugin/dracula.vim: https://github.com/dracula/vim/blob/9fa89296884e47bbadc49ad959e37b9d1c24cafb/after/plugin/dracula.vim#L48

Note I just want to change GitGutterDelete, not DiffDelete.

Following the docs, I put my customization in a ColorScheme autocommand like so (near the top of my vimrc, before calling colorscheme dracula):

augroup Config
  autocmd!
augroup end

autocmd Config ColorScheme dracula call s:handle_colorscheme_dracula()

function! s:handle_colorscheme_dracula() abort
  highlight link CurSearch IncSearch
  highlight! link GitGutterDelete DraculaRed
endfunction

No matter what I try (with or without the bang !), the highlight group linked in the dracula plugin takes precedence:

:verbose hi GitGutterDelete                                                                                                                                                         
GitGutterDelete xxx links to DiffDelete                                                                                                                                             
        Last set from ~/.vim/pack/minpac/start/dracula/after/plugin/dracula.vim line 48

What am I missing? I assume the issue is that the dracula plugin puts files in /after, which is loaded after the vimrc, and uses hi! link.

To reproduce my setup:

  1. Create the following minimal vimrc file. In my demo I have called it minimal.vim:
augroup Config
  autocmd!
augroup end

autocmd Config ColorScheme dracula call s:handle_colorscheme_dracula()

function! s:handle_colorscheme_dracula() abort
  highlight link CurSearch IncSearch
  highlight! link GitGutterDelete DraculaRed
endfunction

filetype plugin indent on
syntax enable
set termguicolors
colorscheme dracula
  1. Put the dracula theme files into the vim runtime path, for example ~/.vim/pack/plugins/start/dracula.
  2. Open vim with vim -N -u ./minimal.vim.
  3. :verbose hi GitGutterDelete

What I expected to happen

I expect the output of :verbose hi GitGutterDelete to show GitGutterDelete xxx links to DraculaRed.

Screenshot

Screenshot 2024-03-12 at 9 53 02 PM

Machine Info

Additional Info

benknoble commented 8 months ago

For plugin groups that are set using after/plugin (which I argued against, IIRC), you probably need to put your own after/plugin/XXX.vim script that does something like

if g:colors_name ==# 'dracula'
  " your highlight changes
endif

Of course note that these plugin files will not be automatically re-sourced when you call :colorscheme.

See even more challenges linked in https://github.com/dracula/vim/pull/85 (where I do, in fact, suggest that after is a bad idea for a colorscheme).

benknoble commented 8 months ago

@dsifford: is time to revisit after?

benknoble commented 8 months ago

https://github.com/dracula/vim/issues/280 also seems related, though I'm trying to page back in a lot of context on that one.

benknoble commented 8 months ago

Is this still true? https://github.com/dracula/vim/issues/280#issuecomment-1096780618

The /after was necessary because some plugins tend to overwrite things that are set in the main colors file.


@adriantrunzo this might work to resolve the "what happens if I :colorscheme again" issue https://github.com/dracula/vim/issues/280#issuecomment-1096937219 but it's kind of a hack

dsifford commented 8 months ago

@benknoble happy to revisit if you feel like you've got the bandwidth

benknoble commented 8 months ago

😅 Frankly my plate is overfull at the moment. I will try to carve out some time to take a stab at this, but any context on how we got here would be useful. Something about other plugins not cooperating??

adriantrunzo commented 8 months ago

@benknoble Thanks for the info and I'm happy to help out with any changes and/or testing. I was, in fact, going to fork this repository and just dump all of the highlight logic from /after into /colors/dracula.vim following examples like https://github.com/nordtheme/vim/blob/main/colors/nord.vim. I can still do that and test it out.

benknoble commented 8 months ago

@benknoble Thanks for the info and I'm happy to help out with any changes and/or testing. I was, in fact, going to fork this repository and just dump all of the highlight logic from /after into /colors/dracula.vim following examples like https://github.com/nordtheme/vim/blob/main/colors/nord.vim. I can still do that and test it out.

That would be very helpful. I expect there will be some problems; in particular, you'll need to test with the relevant plugins to see what happens. Before/after matters to make sure the colors make sense.

dsifford commented 8 months ago

The context for the after was there is a mixed bag of random plugins that overwrite highlight groups and cause the highlighting to look non-uniform. The after approach was just us telling those plugins, "no, don't do that" and overwriting their overwrites.

adriantrunzo commented 8 months ago

I've removed the after directory in my fork: https://github.com/adriantrunzo/dracula-vim/tree/no-after.

I haven't run into any issues yet in my setup, but I'll continue to test out the changes over the coming week. I can confirm that the change solves my recurring issues of not being able to source my vimrc without losing highlights and not being able to easily overwrite highlight links.

in particular, you'll need to test with the relevant plugins to see what happens. Before/after matters to make sure the colors make sense.

Sure, visual regression tests make sense. I am not sure what your expectations are, but I can try the following:

I'll have to dust off my Neovim install.. I suppose you'd want to see comparisons for Vim and Neovim separately.

benknoble commented 8 months ago

That sounds great! If you can't cover it all, that's fine, too. But your help on this is much appreciated (by me, at least, who really doesn't have the time for all those things 😅).

adriantrunzo commented 7 months ago

@benknoble @dsifford I haven't noticed any issues over the past 2 weeks while using my fork. I've opened a draft pull request #321 and started taking before/after screenshots. Please let me know if I am on the right path before I go on taking screenshots.

benknoble commented 7 months ago

I'll take a look. I'll also try to get your branch checked out on my machines to see how it runs.