Created
May 13, 2016 07:36
-
-
Save romgrk/71b119c0baa6b0872f0a88106254ce60 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 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