When I do a search in vim, I like to have my results highlighted and super-visible, so I give them a bright yellow background and a black foreground in my .vimrc.

" When highlighting search terms, make sure text is contrasting colors
:highlight Search guibg=yellow guifg=black

(This is for GUI versions of vim, like MacVim or Gvim; for command-line, you'd use ctermbg and ctermfg.)

But I sometimes use search as a movement, as in c/\foo - "change from the cursor to the next occurrence of foo."

In that case, I don't want all the occurrences of foo to be highlighted.

Can I turn off highlighting in cases where search is used as a movement for a command?

link|improve this question

62% accept rate
feedback

1 Answer

To permanently disable highlighting of searches:

:set nohlsearch
(or)
:set nohls

But probably you want to keep highlight on. On the other hand, if want to temporary get rid of the highlight, type:

:nohlsearch
(or)
:noh

It will stop highlighting the current search, until you search again.

Even though it's not the perfect answer for you, this is a nice workaround, and this is what I use.

link|improve this answer
Actually, I've got an even shorter shortcut for "clear my current search highlighting": I just hit enter if I'm in normal mode. This line is in my .vimrc: :nnoremap <CR> :nohlsearch<CR>/<BS>. It clears the highlighting, starts a new search, and then backspaces to abort the search (thereby clearing the search bar so things look normal again.) This is pretty easy, but I'm so lazy that if I could avoid even having to hit enter, I would like that. :) – Nathan Long Feb 14 '11 at 16:22
I got an even easier shortcut: Alt+/ mapped to nnoremap <M-/> :nohlsearch<CR> (note: Alt+/ does not work on some terminals, but works well inside gvim) – Denilson Sá Feb 14 '11 at 21:09
I don't quite get it. What do you type and what happens? – Nathan Long Feb 15 '11 at 21:55
I've added the remapping thing to my .vimrc. Then, whenever I want to temporary disable the highlighting, I press Alt+/, which is the shortcut to which I mapped it. – Denilson Sá Feb 17 '11 at 17:11
Also... as I said, it's a workaround, not exactly a solution. – Denilson Sá Feb 17 '11 at 17:23
feedback

Your Answer

 
or
required, but never shown

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