This is an example of how highlighted text looks in my vim:

vim screenshot

In the color scheme I am using (/usr/share/vim/vim82/colors/peachpuff.vim) the color is defined like this:

hi Search term=reverse ctermbg=3 guibg=Gold2

When I change this particular color using following command:

:hi Search ctermbg=5

the color of selection does change (I am using vim from terminal, so guibg does not matter). But looks like term=reverse value does not affect anything. I expect that term=reverse should change the color of text itself, so that the highlighted text would become visible. But the colors of text inside and outside the highlighted area are the same. How can it be fixed?

I am using linux, Mate desktop, vim version 8.2.360


I ended up specifying ctremfg colors in Search and several other highlight groups in my vimrc:

highlight Search term=reverse ctermbg=3 ctermfg=0 guibg=Gold2

I am very sure that all the colors were somehow readable in vim 8.1, even though definition of Search highlight group in the colorscheme I am using (peachbuff) did not change.

  • 1
    Just because youre in the terminal doesnt mean guibg doesnt apply: what is :set termguicolor?. term is used when no colors are available (I think), in this case for reverse video (swap foreground and background, like in less). I would try changing the guibg too, and possible setting the foreground if you can’t read certain colors under the highlighting.
    – D. Ben Knoble
    Oct 1, 2020 at 12:13
  • 1
    @D.BenKnoble set termguicolors? reports notermguicolors. I tried to speciy some guibg like this: :hi Search ctermbg=3 guibg=Black - but looks like it affects nothing.
    – lesnik
    Oct 1, 2020 at 12:19

1 Answer 1

  1. term is intended for b&w terminals only. So it has no effect in your case and all you got is a different background. What you want is called cterm.

  2. cterm=reverse actually swaps foreground and background color. So if you highlight Normal text with Search it effectively becomes ctermfg=3 ctermbg=fg. However, it will be different if the "searched" word has some syntax highlighting. Hence I doubt if reverse is good for Search, but, of course, you can make a try.

P.S. In order never to get background==foreground you can do one of:

a) Something like hi Search ctermbg=3 ctermfg=bg (or maybe ctermfg=fg depending on new background value), so highlighted text always has same foreground.

b) Just hi Search cterm=reverse without specifying any additional color (con: could result in many different colorings due to syntax highlighting).

c) hi Search ctermfg=bg ctermbg=fg, so it's always "reversed Normal" (con: "reversed Normal" is often used for "Visual", so it could be confusing).

d) Search harder and find some distinct background color which has good contrast with all syntax elements in this particular color scheme.

  • it does not solve my problem, but still very helpful and makes situation more clear!
    – lesnik
    Oct 1, 2020 at 13:42
  • 1
    @Matt Perhaps you could expand your answer with a specific suggestion on how to set the colors in a way that uses reverse properly in order to ensure there's proper contrast? Something like hi Search cterm=reverse ctermfg=3 ctermfg=NONE perhaps? That's similar to what OP currently has, but it will use black on yellow background and be readable...
    – filbranden
    Oct 1, 2020 at 14:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.