vimtricks.wiki Concise Vim tricks, one at a time.

How do I choose between multiple tag definitions when jumping to a symbol in Vim?

Answer

g<C-]>

Explanation

When a symbol (function, class, variable) is defined in multiple places, CTRL-] blindly jumps to the first match. g<C-]> instead opens an interactive selection list so you can pick the exact definition you want. This is especially valuable in large codebases where interfaces, implementations, and tests all share the same symbol name.

How it works

  • g acts as a modifier that changes the behavior of the following command
  • <C-]> normally jumps to the first tag matching the word under the cursor
  • Combined as g<C-]>, it first checks how many matches exist:
    • If one match: jumps directly (same as CTRL-])
    • If multiple matches: displays a numbered list (:tselect interface) so you can type the number of the entry you want

The tag stack is updated in both cases, so CTRL-t still takes you back after jumping.

Example

With cursor on handleRequest, pressing g<C-]> might show:

  # pri kind tag               file
  1 1   f    handleRequest     src/server.c
  2 1   f    handleRequest     src/proxy.c
  3 1   p    handleRequest     include/server.h
Type number and <Enter> (empty cancels):

Type 2 and <CR> to jump directly to the proxy implementation.

Tips

  • Use :tselect {name} to open the same picker for any symbol by name without moving the cursor
  • :tnext and :tprev cycle through matches after a CTRL-] jump
  • :tags shows the current tag stack so you can see your navigation history
  • Works with any ctags-compatible tag file generated by ctags -R

Next

How do I use a Vimscript expression to compute the replacement text in a substitution?