Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highlight searches in Vim but not substitutions?

Tags:

vim

I know it's possible to stop Vim from highlighting on any search, but is there a way to make it highlight on regular searches but not, for instance, substitutions?

I will often highlight a block of text then do something like:

:s/^/#/

to comment out the whole block. But then I have an ugly yellow bar running up and down the left side of my screen and I have to :noh every time to clear it.

I want highlighting to remain on regular /searches. Is this possible?

like image 435
Derek Avatar asked Feb 13 '13 21:02

Derek


People also ask

How to highlight a search in Vim?

Add set hlsearch in the file. Save the file. Now your search will always be highlighted in vim. For single time use, just use :set hlsearch in vim, which will be in effect for that instance only. how to remove that highlight once i have found out the matches? i pressed escape and the highlight still exists.

How to find the beginning of a search pattern in Vim?

There is a way with Vim to specify where the beginning of the search pattern should start. As an example, suppose we want to find the lines beginning with 'foo', with the word 'bar' somewhere else and then 'magic', but that we only want to highlight 'magic' and everything up to the end to the line. We can use 'zs' for that like this:

How do I use the Super Star(*) Key in Vim?

The super star ( *) key in Vim will search for the word under the cursor and jump forward to the next match. The user can jump to the next matches with the n key. If hlsearch is enabled, it will also highlight the matches. I want to be able to press * and get the highlighted matches and be able to navigate the matches using the n key.

How do I highlight all matches in a search?

To highlight all search matches, set the following option: With the defaults, setting this option causes all text matching the current search to be highlighted using the Search highlight group, which adds a yellow background to the current highlighting. See :help hl-Search, or type :hi Search to see what color you have it set to.


1 Answers

This doesn't answer your question fully but for me having the same problem it helped: I added this command to easily deactivate the highlighting after a search or a search-and-replace

nnoremap <esc> :noh<return><esc>

(from Vim clear last search highlighting)

like image 179
Patrick B. Avatar answered Oct 18 '22 04:10

Patrick B.