[vim/vim] make VISUAL highlight better with bg=dark (#8247)

73 views
Skip to first unread message

Christian Brabandt

unread,
May 24, 2021, 5:24:58 AM5/24/21
to vim/vim, Subscribed

I recently setup my work machine and for some reason, when working with
putty and tmux I cannot see the visual highlight if the background
option is set to dark (which is what I use). I noticed that :hi Visual shows

Visual xxx term=reverse ctermbg=242 guibg=DarkGrey

image
:set term? bg?

  background=dark
  term=tmux-256color

Adding the attribute cterm=reverse helps, so let's make that the
default so that :hi Visual shows:

Visual xxx term=reverse cterm=reverse ctermbg=242 guibg=DarkGrey

image


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/8247

Commit Summary

  • make VISUAL highlight better with bg=dark

File Changes

Patch Links:


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

codecov[bot]

unread,
May 24, 2021, 6:52:31 AM5/24/21
to vim/vim, Subscribed

Codecov Report

Merging #8247 (38342ec) into master (f5409db) will decrease coverage by 86.99%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff             @@

##           master    #8247       +/-   ##

===========================================

- Coverage   89.46%    2.46%   -87.00%     

===========================================

  Files         148      146        -2     

  Lines      166969   161828     -5141     

===========================================

- Hits       149373     3990   -145383     

- Misses      17596   157838   +140242     
Flag Coverage Δ
huge-clang-none ?
huge-gcc-none ?
huge-gcc-testgui ?
huge-gcc-unittests 2.46% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/highlight.c 8.00% <ø> (-82.46%) ⬇️
src/sha256.c 0.00% <0.00%> (-97.96%) ⬇️
src/digraph.c 0.00% <0.00%> (-97.78%) ⬇️
src/gui_gtk_f.c 0.00% <0.00%> (-97.54%) ⬇️
src/match.c 0.00% <0.00%> (-97.13%) ⬇️
src/crypt_zip.c 0.00% <0.00%> (-97.06%) ⬇️
src/evalbuffer.c 0.00% <0.00%> (-96.83%) ⬇️
src/debugger.c 0.00% <0.00%> (-96.62%) ⬇️
src/libvterm/src/rect.h 0.00% <0.00%> (-96.56%) ⬇️
src/textprop.c 0.00% <0.00%> (-96.45%) ⬇️
... and 135 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f5409db...38342ec. Read the comment docs.

Shane-XB-Qian

unread,
May 24, 2021, 8:46:52 PM5/24/21
to vim/vim, Subscribed

Adding the attribute cterm=reverse helps, so let's make that the
default so that :hi Visual shows:

i think it's not a good idea, at my side, if set to 'reverse', the chars' color messed up together, to me looks default 'ctermbg=242' is clear enough..

image

matveyt

unread,
May 25, 2021, 12:13:26 AM5/25/21
to vim/vim, Subscribed

Color 242 should map to rgb 6c6c6c that is normally well-distinguishable from black. So it rather looks as misconfiguration of some sort. And setting "reverse"...

src/highlight.c:426

// Reverse looks ugly, but grey may not work for 8 colors.  Thus let it
// depend on the number of colors available.
// With 8 colors brown is equal to yellow, need to use black for Search fg
// to avoid Statement highlighted text disappears.
// Clear the attributes, needed when changing the t_Co value.
if (t_colors > 8)
    do_highlight((char_u *)(*p_bg == 'l'
	? "Visual cterm=NONE ctermbg=LightGrey"
	: "Visual cterm=NONE ctermbg=DarkGrey"), FALSE, TRUE);
else
{
    do_highlight((char_u *)"Visual cterm=reverse ctermbg=NONE",
						            FALSE, TRUE);
    ...

There's a different trick: :hi Visual cterm=NONE ctermfg=bg ctermbg=fg. Then it does not depend on extra color(s) and the whole selected area will uniformly look as "reverse normal" that is guaranteed to have enough contrast. However, in this case we also temporarily lose foreground coloring, so I don't think that everyone will be happy. Personally I prefer this one (in my own color scheme), but the major part of other color schemes seem to adopt "extra special selection background" as in Vim default.

Christian Brabandt

unread,
May 28, 2021, 6:50:15 AM5/28/21
to vim/vim, Subscribed

Color 242 should map to rgb 6c6c6c that is normally well-distinguishable from black. So it rather looks as misconfiguration of some sort. And setting "reverse"...

Yes, but if the color would not be visible, setting reverse should not have an effect.

matveyt

unread,
May 28, 2021, 11:35:24 AM5/28/21
to vim/vim, Subscribed

"Reverse" swaps foreground and background colors, so it will have some effects anyway (these cyan and magenta background spots in picture no. 2). You probably mean that reverse text got color 242 while still seeming distinguishable from the black background. I admit I don't know why is this. Maybe it's not. Maybe it only seems distinguishable while being on cyan background...

Bram Moolenaar

unread,
May 28, 2021, 1:31:04 PM5/28/21
to vim/vim, Subscribed

I cannot reproduce the problem. Perhaps Vim thinks the terminal supports 256 colors, but it actually only supports 8 or 16 colors?
Using "reverse" looks quite bad when the terminal is correctly setup.
What is the value of t_Co for you? What happens if you set t_Co to 16?

Christian Brabandt

unread,
May 30, 2021, 1:15:43 PM5/30/21
to vim/vim, Subscribed

Closed #8247.

Reply all
Reply to author
Forward
0 new messages