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
gacts 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 (
:tselectinterface) so you can type the number of the entry you want
- If one match: jumps directly (same as
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 :tnextand:tprevcycle through matches after aCTRL-]jump:tagsshows the current tag stack so you can see your navigation history- Works with any ctags-compatible tag file generated by
ctags -R