Vim: How to change the highlight color for search hits and quickfix selection

ColorsVim

Colors Problem Overview


I am using the desert colorscheme, which uses white text on orange background for highlighting search hits. The same pattern is used for the selected entry in the quickfix window.

White on orange is not very readable. How do I change that in .vimrc?

Edit: Thanks for the fast reply, for the desert scheme I am now using the following search highlight modification:

highlight Search guibg='Purple' guifg='NONE'

Purple is quite easy to detect visually and it is IMHO not used for syntax coloring in the desert scheme.

Colors Solutions


Solution 1 - Colors

Look at $VIMRUNTIME/colors/desert.vim. Color mappings are defined there with the hi[ghlight] command. The search highlighting is defined as

hi Search guibg=peru guifg=wheat

for the GUI and

hi Search cterm=NONE ctermfg=grey ctermbg=blue

for terminals.

You can override this setting in your .vimrc using the same command after you select your colorscheme. Type :h hi for help.

Solution 2 - Colors

For me I have to also add hlsearch under syntax on in the ~/.vimrc

set hlsearch
hi Search ctermbg=LightYellow
hi Search ctermfg=Red

Inside VIM you can also do: :highlight Search ctermfg=yellow to change it on the fly.

  • ctermfg is for foreground color
  • ctermbg is for background color

available colors from the vi documentation page are:

*cterm-colors*

NR-16   NR-8    COLOR NAME 
0       0       Black
1       4       DarkBlue
2       2       DarkGreen
3       6       DarkCyan
4       1       DarkRed
5       5       DarkMagenta
6       3       Brown, DarkYellow
7       7       LightGray, LightGrey, Gray, Grey
8       0*      DarkGray, DarkGrey
9       4*      Blue, LightBlue
10      2*      Green, LightGreen
11      6*      Cyan, LightCyan
12      1*      Red, LightRed
13      5*      Magenta, LightMagenta
14      3*      Yellow, LightYellow
15      7*      White

Solution 3 - Colors

In my case the line in the QuickFix window was showing an unreadable grey on cyan, which was different to my search results (a more pleasing black on peach) This was confirmed by the command

:hi

which showed the formatting of QuickFixLine and Search as being set to

QuickFixLine   xxx term=reverse guibg=Cyan
Search         xxx term=reverse ctermfg=0 ctermbg=222 guifg=#000000 guibg=#FFE792

where xxx had a sample format,

I appended the following line to my ~/.vimrc

hi QuickFixLine term=reverse ctermbg=52

and now in my terminal window I have a more pleasing dark red background. Running hi: shows the addition of the background colour change for my ternimal:

QuickFixLine   xxx term=reverse ctermbg=52 guibg=Cyan

(vim 8 on MacOS High Sierra in iTerm2, with molokai theme)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJuveView Question on Stackoverflow
Solution 1 - ColorsFerdinand BeyerView Answer on Stackoverflow
Solution 2 - ColorsLeOn - Han LiView Answer on Stackoverflow
Solution 3 - ColorsSpangenView Answer on Stackoverflow