How can I highlight all occurrence of a selected word in GVim, like in Notepad++?
In Normal mode:
:set hlsearch
Then search for a pattern with the command /
in Normal mode, or <Ctrl>o
followed by /
in Insert mode. *
in Normal mode will search for the next occurrence of the word under the cursor. The hlsearch
option will highlight all of them if set. #
will search for the previous occurrence of the word.
To remove the highlight of the previous search:
:nohlsearch
You might wish to map :nohlsearch<CR>
to some convenient key.
First (or in your .vimrc):
:set hlsearch
Then position your cursor over the word you want highlighted, and hit *
.
hlsearch
means highlight all occurrences of the current search, and *
means search for the word under the cursor.
Enable search highlighting:
:set hlsearch
Then search for the word:
/word<Enter>
My favorite for doing this is the mark.vim plugin. It allows to highlight several words in different colors simultaneously.
Example Screenshot
I know than it's a really old question, but if someone is interested in this feature, can check this code http://vim.wikia.com/wiki/Auto_highlight_current_word_when_idle
" Highlight all instances of word under cursor, when idle.
" Useful when studying strange source code.
" Type z/ to toggle highlighting on/off.
nnoremap z/ :if AutoHighlightToggle()<Bar>set hls<Bar>endif<CR>
function! AutoHighlightToggle()
let @/ = ''
if exists('#auto_highlight')
au! auto_highlight
augroup! auto_highlight
setl updatetime=4000
echo 'Highlight current word: off'
return 0
else
augroup auto_highlight
au!
au CursorHold * let @/ = '\V\<'.escape(expand('<cword>'), '\').'\>'
augroup end
setl updatetime=500
echo 'Highlight current word: ON'
return 1
endif
endfunction
The *
key will highlight all occurrences of the word that is under the cursor.