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 of cterm)
  • guifg is for foreground color (as opposite of ctermfg)
  • guibg is for background color (as opposite of ctermbg)
Share:
12,699
MLister
Author by

MLister

Updated on September 18, 2022

Comments

  • MLister
    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
      phuclv almost 7 years
      previously I used set cursorline to help finding the search result. But set hlsearch works better
  • demure
    demure almost 11 years
    You can add the first two settings to your ~/.vimrc, without the leading :. You can also bind :noh to a key, for ease of use.