Skip to content

Instantly share code, notes, and snippets.

@romainl
Last active January 22, 2023 14:54
Show Gist options
  • Save romainl/a11c6952f012f1dd32c26fad4fa82e43 to your computer and use it in GitHub Desktop.
Save romainl/a11c6952f012f1dd32c26fad4fa82e43 to your computer and use it in GitHub Desktop.
Print declaration of word under the cursor
function! ShowDeclaration(global) abort
let pos = getpos('.')
if searchdecl(expand('<cword>'), a:global) == 0
let line_of_declaration = line('.')
execute line_of_declaration . "#"
else
echo 'Sorry, no declaration found.'
endif
call cursor(pos[1], pos[2])
endfunction
nnoremap sd :call ShowDeclaration(0)<CR>
nnoremap sD :call ShowDeclaration(1)<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment