sainnhe / gruvbox-material

Gruvbox with Material Palette
MIT License
1.96k stars 166 forks source link

fix(vim): invisible git DiffText and coc Search highlight when cursorline is set #214

Closed lekemula closed 1 month ago

lekemula commented 2 months ago

Hi there,

I was facing the same issue like 80331fb but when git diffing with pope/vim-fugitive and using neoclide/coc.nvim LSP find references functionality (solargraph in my case).

Thanks to the detailed investigation and solution on the previous fix, I could replicate and fix both these cases. Though I must say that this is the first time I'm doing Vim changes regarding the theeming, so take it with a grain of salt, since I'm not entirely sure how the fix works. This is mainly reverse-engineering :D.

Git diff

Before

After

Coc LSP find-references

Before

image_1727001658036_0

After

image_1727001252357_0

Cheers!

antoineco commented 2 months ago

Thanks for the investigation and fix! Really appreciate the thorough documentation and screenshots 👍

Neovim user here, so I'm going to configure my Vim and try replicating the issue with IncSearch to ensure that tweaking it is really necessary.

Small note: in the "Git diff" section of the issue description both screenshots are identical. But I get the idea of what may be happening in the "cursor is NOT on the diff line" case.

lekemula commented 2 months ago

Small note: in the "Git diff" section of the issue description both screenshots are identical. But I get the idea of what may be happening in the "cursor is NOT on the diff line" case.

Aggh, pasted the wrong screenshot there - I updated it! Thanks for the quick response, and for double-checking the IncSearch 👍

antoineco commented 2 months ago

Could you please share what version of Vim you are currently using? I am having trouble reproducing the issue with the Search highlight in combination with cursorline on 9.0 and 9.1:

image
lekemula commented 2 months ago

Sure, here you go:

Details

``` ❯ vim --version VIM - Vi IMproved 9.1 (2024 Jan 02, compiled Jun 18 2024 19:01:23) macOS version - arm64 Included patches: 1-500 Compiled by Homebrew Huge version without GUI. Features included (+) or not (-): +acl +file_in_path +mouse_urxvt -tag_any_white +arabic +find_in_path +mouse_xterm -tcl +autocmd +float +multi_byte +termguicolors +autochdir +folding +multi_lang +terminal -autoservername -footer -mzscheme +terminfo -balloon_eval +fork() +netbeans_intg +termresponse +balloon_eval_term +gettext +num64 +textobjects -browse -hangul_input +packages +textprop ++builtin_terms +iconv +path_extra +timers +byte_offset +insert_expand +perl +title +channel +ipv6 +persistent_undo -toolbar +cindent +job +popupwin +user_commands -clientserver +jumplist +postscript +vartabs +clipboard +keymap +printer +vertsplit +cmdline_compl +lambda +profile +vim9script +cmdline_hist +langmap -python +viminfo +cmdline_info +libcall +python3 +virtualedit +comments +linebreak +quickfix +visual +conceal +lispindent +reltime +visualextra +cryptv +listcmds +rightleft +vreplace +cscope +localmap +ruby +wildignore +cursorbind +lua +scrollbind +wildmenu +cursorshape +menu +signs +windows +dialog_con +mksession +smartindent +writebackup +diff +modify_fname +sodium -X11 +digraphs +mouse +sound -xattr -dnd -mouseshape +spell -xfontset -ebcdic +mouse_dec +startuptime -xim +emacs_tags -mouse_gpm +statusline -xpm +eval -mouse_jsbterm -sun_workshop -xsmp +ex_extra +mouse_netterm +syntax -xterm_clipboard +extra_search +mouse_sgr +tag_binary -xterm_save -farsi -mouse_sysmouse -tag_old_static system vimrc file: "$VIM/vimrc" user vimrc file: "$HOME/.vimrc" 2nd user vimrc file: "~/.vim/vimrc" 3rd user vimrc file: "$XDG_CONFIG_HOME/vim/vimrc" user exrc file: "$HOME/.exrc" defaults file: "$VIMRUNTIME/defaults.vim" fall-back for $VIM: "/opt/homebrew/share/vim" Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H -DMACOS_X -DMACOS_X_DARWIN -g -O2 -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 Linking: clang -o vim -lm -lncurses -lsodium -liconv -lintl -framework AppKit -L/opt/homebrew/opt/lua/lib -llua5.4 -mmacosx-version-min=13.6 -fstack-protector-strong -L/opt/homebrew/opt/perl/lib/perl5/5.38/darwin-thread-multi-2level/CORE -lperl -L/opt/homebrew/opt/python@3.12/Frameworks/Python.framework/Versions/3.12/lib/python3.12/config-3.12-darwin -lpython3.12 -framework CoreFoundation -lruby.3.3 -L/opt/homebrew/Cellar/ruby/3.3.3/lib ```

Can you also show me how to trigger the Search highlight normally? Maybe it was just an issue with Coc?

antoineco commented 2 months ago

I tested with this minimal vimrc:

set termguicolors background=dark cursorline hlsearch
syntax on
colorscheme gruvbox-material

I then performed a search with /start.line in the Ruby file used as example and moved my cursor to the line showing the result.

If you move your cursor to the text with the problematic highlight and execute the command below you might be able to see whether some plugin is influencing the hightlight group:

echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')

There is unfortunately no better way of showing precisely what highlight group is being applied in the "classic" Vim. For example, mine is printing the line below, without even mentionning Search despite it being clearly applied under my cursor:

['rubyModuleBlock', 'rubyModuleBlock', 'rubyModuleBlock', 'rubyClassBlock', 'rubyMethodBlock', 'rubyDoBlock', 'rubyDoBlock', 'rubyKeywordAsMethod']
lekemula commented 2 months ago

It appears that in my case I didn't have the hlsearch set. After setting I do have the same behaviour as yours:

image

However, the issue still remains for the Coc window, after running find-references (eg. nmap <silent> grf <Plug>(coc-references)). I suppose, the only way to reproduce this is by triggering this action, for a LSP of your choice.

Running echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")') on that same window gives only [CocLocationLine]

Screenshot 2024-09-24 at 22 09 06

As we can see above, the problem lies inside the window that coc lists the references, and not the source code.

FWIW, the way I came to this fix, was sort of reverse engineering - by running :highlight and noticing this config:

image

Let me know if you need more details.

lekemula commented 1 month ago

Well, I'm happy that I had a correct guess there. 😅

Thanks for the explainer @antoineco, I learned a lot about vim styling from this small PR! ❤️