The answers proposing :noh
or :nohlsearch
(e.g., Matt McMinn’s) are correct for temporarily disabling search highlighting – as asked in the original question.
I thought I'd contribute a mapping that I find useful in Normal mode:
nnoremap <C-L> :nohlsearch<CR><C-L>
By default, CtrlL in Vim clears and redraws the screen. A number of command line programs (mostly those using the GNU Readline library, such as Bash) use the same key combination to clear the screen. This feature is useful in the situation where a process running in the background prints to the terminal, over-writing parts of the foreground process.
This Normal mode mapping also clears the highlighting of most recent search term before redrawing the screen. I find the two features complement each other and it’s convenient to use one CtrlL for both actions together rather than create a separate mapping for disabling search highlighting.
NB: noremap
is used rather than map
as otherwise, the mapping would be recursive.
Tip: I usually remap Caps Lock to Ctrl to make it easier to type such key combinations; the details for doing this depend on your choice of OS / windowing system (and are off-topic for this answer). Both the following tips include information on mapping Caps Lock to Ctrl as well as Esc:
nnoremap <esc> :noh<return><esc>
solution suggested by @StewartJohnson works nicely in GUI vim, but causes problems with arrow keys and other ESC-encoded keys when running vim in a terminal. Don't put it in your~/.vimrc
without wrapping it inif has('gui_running')
...end
. – jbyler