Auto highlight current word when idle
From Vim Tips Wiki
Tip 572 Previous Tip • Next Tip
Created: September 30, 2003 Complexity: basic Author: mosh Minimum version: 6.0 Karma: 23/10 Imported from: Tip#572
" Highlight all instances of word under cursor, when idle.
" Useful when studying strange source code.
" Turn on/off with z/ (or key of your choice)
map z/ :call Auto_Highlight_Toggle()<CR>
function! Auto_Highlight_Cword()
exe "let @/='\\<".expand("<cword>")."\\>'"
endfunction
function! Auto_Highlight_Toggle()
if exists("#CursorHold#*")
au! CursorHold *
let @/=''
else
set hlsearch
set updatetime=500
au! CursorHold * nested call Auto_Highlight_Cword()
endif
endfunction
[edit] Comments
I would suggest placing the CursorHold event inside an autocommand group (augroup); the way this is right now would clobber my other CursorHold autocommands.
Categories: Review | VimTip | Syntax
