tags:

views:

1060

answers:

7

I have :set hlsearch as default value.

When I search for something, search terms get highlighted. However many times I want to get rid of the highlight, so I do :set nohlsearch. In this way I get rid of highlights for the time being.

However if I do a new search then search terms are not highlighted.

I would like to hit ESC and ESC to get rid of highlights and then set back set hlsearch.

Any suggestions?

+14  A: 

Try the :noh command.

Michael Krelin - hacker
How would you map :noh to <C-l> but keep <C-l>'s redraw behavior intact?
meder
Not sure if that was part of the assignment, but if you insist, why not add `:redraw` to the mapping?
Michael Krelin - hacker
Thanks, used vim for years but was not aware of that one. I just wonder if it is possible for my fingers to unlearn /lkjlkj ?
codeape
it is my experience that fingers are very eager to learn new things, it just takes them ages to forget old ones ;-)
Michael Krelin - hacker
A: 

you could search for something not in the text file. Nothing will be highlighted in this case. (e.g. /349i5u9sgh)

Ben Hughes
that's what I do now. I am looking for a better alternative.
Roger
+1  A: 

Try this:

set hlsearch!
nnoremap <F12> :set hlsearch!<CR>

and hit F12 to clear when desired. Use :noh in command mode to clear.

John Feminella
+2  A: 

I use

/pleasedisablehighlightthanks

command. Or just

/qewrufhiqwe

But you should be carefult not to mix this with the following command!

/qewrufhiqew
Pavel Shved
It would have the same effect like that of `:noh`, but you have to be careful not to hit something that can be found ;-)
Michael Krelin - hacker
This is the technique I've used - but the :noh turns of the highlights too (leaving the next search in highlight mode), so it is 'better'. (All else apart, I end up with a 'Pattern not found: kkk' error message at the bottom, which has to be cleaned up to.
Jonathan Leffler
I just use /asdf, it's shorter :)
Noah
+4  A: 
:noremap <silent> <c-l> :nohls<cr><c-l>

This would redraw the screen and clear any search terms with Control-L, handy :) easier than reaching up to the F keys.

meder
+1  A: 

I have the following in my .vimrc:

map <silent> <C-N> :let @/=""<CR>
jqno
Can someone walk me throug what's happening in this code. I don't get it.
Roger
`@/` is the register that contains the latest search term. This command clears that register, which has the effect that the search highlights disappear. It's sort of equivalent to `:nohls`.
jqno
I have the same :let mapped to <leader><leader> -- its a comfortable reach up to \
zen
+1  A: 

This might suit your needs:

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

With a little tinkering you can make it work in insert mode.

Mosh
As there is no messaging on SO other than comments, I will note here that I responded to your comment somewhere else:http://stackoverflow.com/questions/2268324/g-showing-functions-and-comments-below/2268357#2268357
DigitalRoss