4

I'm using Exuberant Ctags to generate a tags file to use with Vim. However, in our project, we have javascript that makes remote procedure calls to the server (PHP). Functions like getUsers are thus called rpc_getUsers on the serverside. Is there a way to properly use things like ctrl+] to jump to the associated function on the serverside, assuming it's a standard prefix/list of prefixes?

3

You could use a mapping from Ctrl+] to a custom function, similar to the one described at :help CursorHold-example:

A nice addition is to highlight the found tag, avoid the ":ptag" when there
is no word under the cursor, and a few other things: >

  :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 ctermbg=green guibg=green
  :      exe 'match previewWord "\%' . line(".") . 'l\%' . col(".") . 'c\k*"'
  :      wincmd p                       " back to old window
  :    endif
  :  endif
  :endfun

Perhaps your function could try tag or ptag, and in the catch clause it could try again including the rpc_ prefix.

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.