Skip to content

Instantly share code, notes, and snippets.

@romgrk
Created May 13, 2016 07:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romgrk/71b119c0baa6b0872f0a88106254ce60 to your computer and use it in GitHub Desktop.
Save romgrk/71b119c0baa6b0872f0a88106254ce60 to your computer and use it in GitHub Desktop.
" File: definition.vim
" Author: romgrk
" Date: 13 May 2016
" Description: Jump where the given expression was last set.
" !::exe [so %]
command! -nargs=* -complete=expression Goto call <SID>goto(<q-args>)
" Example mappings:
" nmap <leader>gc :Goto command<space>
" nmap <leader>gf :Goto function<space>
" nmap <leader>gm :Goto nmap<space>
" nmap <leader>ga :Goto abbrev<space>
function! s:goto (str)
let out = ''
try
redir => out
silent! execute 'verbose' a:str
redir END
catch /.*/
echom v:exception
" g_free(out);
return
endtry
let lastset = matchstr(out, 'Last set from \zs\f\+')
"echom lastset
execute 'edit ' . lastset
let what = matchstr(a:str, '\w\+')
let name = matchstr(a:str, '\v\s*[^ ]\s+\zs\w+')
" / [com|fu|se|nm|…] [mand|nction|t|ap]? [!]? <space> TAG
let pattern = '\s*' . what[0:1] . '(' . what[2:] . ')?\w*!?\s+.*' . name
silent! call search('\v' . pattern)
"echom pattern
endfunc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment