How to change search result highlight in vi?
12,699
Solution 1
Switch to vim, and use :set hlsearch
You can then use :highlight Search ctermfg=yellow
to customize; where:
-
cterm
is for formating -
ctermfg
is for foreground color -
ctermbg
is for background color
see :help highlight
link
You can then use :noh
to temporarily hide the last search highlight.
Solution 2
Also, FYI, in GUI version of Vim:
-
gui
is for formatting (as opposite ofcterm
) -
guifg
is for foreground color (as opposite ofctermfg
) -
guibg
is for background color (as opposite ofctermbg
)
Author by
MLister
Updated on September 18, 2022Comments
-
MLister over 1 year
The scenario: I log on a server using ssh, and search for keywords in a log file using
vi
.The problem: at the moment, the results of a search is only highlighted by a cursor
_
below the searched word, which is not very easy to find on a screen of log messages.The question: how can I change the highlighting of the search results to something more noticeable? e.g. different background and foreground colors on the whole word.
-
phuclv almost 7 yearspreviously I used
set cursorline
to help finding the search result. Butset hlsearch
works better
-
-
demure almost 11 yearsYou can add the first two settings to your
~/.vimrc
, without the leading:
. You can also bind:noh
to a key, for ease of use.