Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

vim

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.


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

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)