Skip to content

Instantly share code, notes, and snippets.

@dahu
Created September 15, 2012 03:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dahu/3726230 to your computer and use it in GitHub Desktop.
Save dahu/3726230 to your computer and use it in GitHub Desktop.
Automatically highlight word under cursor if it appears more than once in the file.
" Clean-up of Swicher's Highlighter()
" Barry Arthur 2012-09-15
function! Highlighter()
let word_cursor = escape(expand('<cword>'), ".*[]\\")
redir => output
silent! execute '%s/\<'.word_cursor.'\>//gen'
redir END
if output != ""
if str2nr(split(output)[0]) > 1
execute printf('match IncSearch /\<%s\>/', word_cursor)
endif
normal ``
endif
endfunction
augroup Highlighter
au!
au CursorMoved * call Highlighter()
augroup END
set updatetime=300
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment