0

This post is connected with the following one.

Jumping from function definition tag to prototype tag

Somehow, I did what it is mentioned there. Now, when I generate my tags file using the option --c-kinds=+p and I do CRTL+] it will jump directly to the prototype function.

However, sometimes I am in lines of code where a particular function is being used and I would like to be able to decide if I want to go to the function definition or the function prototype.

For example, using CTRL+] goes to the definition, and using CTRL+[ goes to the prototype. Is this easy to do?

  • 1
    I always use g<C-]> if there are multiple matches. Does that work for you? I can add it as an answer. – D. Ben Knoble Jun 7 at 12:42
  • Ok, that's not exactly what I was looking for, but that's a trick I didn't know and it helps. – Javier Galan Jun 10 at 17:36
0

An alternative is g<C-]>, which lets one choose from multiple tag matches if they exists.

1

:h 'tagfunc' (Vim 8.1.1228 and up) specifies a function to be used to perform tag searches. You can use :h taglist() to get a list of tags and filter it inside your custom tagfunc.

nnoremap <silent> <c-f12> :call <sid>tag("<sid>get_dec_tag", expand('<cword>'))<cr>
nnoremap <silent> <s-f12> :call <sid>tag("<sid>get_def_tag", expand('<cword>'))<cr>

" prototype tagfunc
function! s:get_dec_tag(pattern, flags, info)
  return filter(taglist(a:pattern), 'v:val.kind =~# "^p"')
endfunction

" function tagfunc
function! s:get_def_tag(pattern, flags, info)
  return filter(taglist(a:pattern), 'v:val.kind =~# "^f"')
endfunction

" setup tagfunc, exec :tjump with name, restore tagfunc
function! s:tag(tagfunc, name) abort
  try
    let oldfunc = &tagfunc
    let &tagfunc = a:tagfunc
    exec 'tjump' a:name
  catch /^Vim\%((\a\+)\)\=:E426:/
    echohl ErrorMsg
    echom v:exception
    echohl None
  finally
    let &tagfunc = oldfunc
  endtry
endfunction

Note that i use <c-12> and <s-12> in above script, not sure it's a good idea to change behavior of <c-]>.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.