Home » Questions » Computers [ Ask a new question ]

How do I keep vim from highlighting matches after a replace?

How do I keep vim from highlighting matches after a replace?

I have set hlsearch in my ~/.vimrc. This is normally very useful, but it's annoying to have to do :noh after I do a replace like '<,'>s/$/',/ (which highlights the end of every line after I run it). How do I get vim to not highlight after replacing like this?

Asked by: Guest | Views: 252
Total answers/comments: 2
bert [Entry]

"If you don't want to permanently disable, you can bind a key to toggle the highlight as suggested in this answer to a similar question on stackoverflow.

map <F12> :set hls!<CR>
imap <F12> <ESC>:set hls!<CR>a
vmap <F12> <ESC>:set hls!<CR>gv

If you want to permanently disable the highlight:

11.1. After I searched for a text with a pattern, all the matched text
stays highlighted. How do I turn off the highlighting
temporarily/permanently?

The 'hlsearch' option controls whether all the matches for the last
searched pattern are highlighted or not. By default, this option is not
enabled. If this option is set in a system-wide vimrc file, then you can
turn off the search highlighting by using the following command:

:set nohlsearch

(from the VIM FAQ)"
bert [Entry]

I just type "/asdf" (assuming "asdf" is not in the file) to get rid of the highlighting. I know it's pretty simplistic, but it works for me.