VIM: How to set default color on search based syntax highlighting
Solution 1
All syntax colors, including the search highlight color, are set by changing a highlight group rather than an option. You set these groups with the :highlight
command. For example I have changed search highlighting from yellow a bright turquoise:
:highlight Search guibg=Turquoise4
I have also changed the IncSearch
color, which is the color when 'incsearch'
is set:
:highlight IncSearch gui=underline,bold guifg=White guibg=Red3
See :help :highlight
and :help highlight-groups
.
Solution 2
Figured it out. In /etc/vimrc under the "syntax on" line add:
hi Search ctermbg=red
hi Search ctermfg=white
This example will give you a red block with white text while searching files with VIM. Inside VIM you can also do:
:highlight Search ctermfg=yellow
To change it on the fly.
Related videos on Youtube
user53029
Updated on September 18, 2022Comments
-
user53029 over 1 year
Currently my /etc/vimrc file is set to the following: (
if &t_Co > 2 || has("gui_running") syntax on set hlsearch endif filetype plugin on if &term=="xterm" set t_Co=8 set t_Sb=^[[4%dm set t_Sf=^[[3%dm endif
My problem is that whenever I am in VIM and search for a string when it finds it it highlights it in a bright yellow block. This not not a problem unless I try to find text that is white, then it makes it very difficult to see. I have tried changing the line:
set hlsearch="another_color"
But I get an error when trying open back up the file after saving.
Error detected while processing /etc/vimrc: line 51: E474: Invalid argument: hlsearch=light
In this block of code something tells me this controls background and foreground colors, but I am not sure if that pertains to the "hlsearch" option.
if &term=="xterm" set t_Co=8 set t_Sb=^[[5%dm set t_Sf=^[[6%dm endif
I have tried changing the 5 and 6 to different numbers and that has no effect. I still have a yellow highlight box for searched text.
So my questions are:
1) Where is this "default" yellow color coming from?
2) How do I change it to something else?