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.

| improve this question | | | | |
  • previously I used set cursorline to help finding the search result. But set hlsearch works better – phuclv May 15 '17 at 7:28

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.

| improve this answer | | | | |
  • 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. – demure Jun 3 '13 at 18:47

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)
| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.