views:

2176

answers:

9

I search for "nurple" in a file. I found it, great. But now, every occurrence of "nurple" is rendered in sick black on yellow. Forever.

Forever, that is, until I search for something I know won't be found, such as "asdhfalsdflajdflakjdf" simply so it clears the previous search highlighting.

Can't I just hit a magic key to kill the highlights when I'm done searching?

+18  A: 

:noh will do the trick. (short for nohighlight)

Lee
+13  A: 

Just put this in your .vimrc

" <Ctrl-l> redraws the screen and removes any search highlighting.
nnoremap <silent> <C-l> :nohl<CR><C-l>
Lucas S.
Oooh, that's a goodie. I've been using /@@<ENTER> which works as long as there's no @@ in my files. I must modify my vimrc NOW!
paxdiablo
This is great, cured a lot of my headaches!I think ,it's better to use the full command in vimrc (:nohlsearch) to avoid conflicts in future.
Amit
+2  A: 
      *:noh* *:nohlsearch*
:noh[lsearch]    Stop the highlighting for the 'hlsearch' option.  It
      is automatically turned back on when using a search
      command, or setting the 'hlsearch' option.
      This command doesn't work in an autocommand, because
      the highlighting state is saved and restored when
      executing autocommands |autocmd-searchpat|.
      Same thing for when invoking a user function.

Found it just under the :help #

Which i keep hitting all the time which highlights all the words on the current page like the current one :)

Kent Fredric
+3  A: 

You could put this in your .vimrc file to prevent hilighting alltogether, if you don't find it useful (like me).

set nohlsearch
Daniel Bruce
+1  A: 

There is hlsearch and nohlsearch. :help hlsearch will provide more information. If you want to bind F12 to toggle it on/off you can use this:

map     <F12>   :nohlsearch<CR>
imap    <F12>   <ESC>:nohlsearch<CR>i
vmap    <F12>   <ESC>:nohlsearch<CR>gv
Jeffrey Vanneste
+3  A: 

/lkjasdf has always been faster than :noh for me

jon
Doing this in front of someone who knew Vim better than I did is how I learned about :nohls.
Pi
+9  A: 

Then I prefer this:

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

And why? Because it toggles the switch: if highlight is on, then pressing turns it off. And vica cersa. HTH.

Zsolt Botykai
This can also be accomplished with the "invhlsearch" setting.
Max
A: 

I search so often that I've found it useful to map the underscore key to remove the search highlight:

nnoremap <silent> _ :nohl<CR>
+1  A: 

I have this in my .vimrc:

nnoremap ; :set invhlsearch<CR>

This way, ; will toggle search highlighting. Normally, the ; key repeats the latest t/T/f/F command, but I never really used that functionality. I find this setting much more useful, because I can change search highlighting on and off very quickly, and easily get a sense of where my search results are, at a glance.

Max