Skip to content

Instantly share code, notes, and snippets.

@johnhowe
Created August 9, 2010 14:08
Show Gist options
  • Save johnhowe/515459 to your computer and use it in GitHub Desktop.
Save johnhowe/515459 to your computer and use it in GitHub Desktop.
au! CursorHold *.[ch] nested call PreviewWord()
func PreviewWord()
if &previewwindow " don't do this in the preview window
return
endif
let w = expand("<cword>") " get the word under cursor
if w =~ '\a' " if the word contains a letter
" Delete any existing highlight before showing another tag
silent! wincmd P " jump to preview window
if &previewwindow " if we really get there...
match none " delete existing highlight
wincmd p " back to old window
endif
" Try displaying a matching tag for the word under the cursor
try
exe "ptag " . w
catch
return
endtry
silent! wincmd P " jump to preview window
if &previewwindow " if we really get there...
if has("folding")
silent! .foldopen " don't want a closed fold
endif
call search("$", "b") " to end of previous line
let w = substitute(w, '\\', '\\\\', "")
call search('\<\V' . w . '\>') " position cursor on match
" Add a match highlight to the word at this position
hi previewWord term=bold ctermfg=red guibg=NONE
exe 'match previewWord "\%' . line(".") . 'l\%' . col(".") . 'c\k*"'
wincmd p " back to old window
endif
endif
endfun
set previewheight=20
set updatetime=500
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment