History Report a problem
Article Edit this page Discussion

Auto highlight current word when idle

From Vim Tips Wiki

Jump to: navigation, search

Tip 572 Previous TipNext 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.


Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto
Pushing Daisies
Legend of Zelda Wiki
Terminator Wiki
Everquest II Wiki
Astronomy Wiki
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions


Vote for featured Wikia!

Send this article to a friend
"Auto highlight current word when idle"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation