Wiki

by yszheda

View project onGitHub

Tip 103: Navigate Keyword Definitions with Vim's Tag Navigation Commands

Return to the top: <<Practical Vim>>

Jump to a Keyword Definition

  • <C-]> makes our cursor jump from the keyword under the cursor to the definition.
  • <C-t>: back trace the tag history

References:

# If you open the file in vim,
# then you can \"ayy@a the next line to execute the vim command: 
:h tag-stack

Specify Where to Jump to When a Keyword Has Multiple Matches

  • If a tag in the current buffer matches the keyword, it gets the highest priority.

References:

# If you open the file in vim,
# then you can \"ayy@a the next line to execute the vim command: 
:h tag-priority
  • g<C-]> command presents a list of choices from the tag match list.

Use Ex Commands

  • :tag {keyword}: like <C-]>
  • :tjump {keyword}: like g<C-]>

References:

# If you open the file in vim,
# then you can \"ayy@a the next line to execute the vim command: 
:h :tag
:h :tjump
  • can accept a regular expression when used in the form :tag /{pattern} or :tjump /{pattern}
Command Effect
<C-]> Jump to the first tag that matches the word under the cursor
g<C-]> Prompt user to select from multiple matches for the word under the cursor. If only one match exists, jump to it without prompting
:tag {keyword} Jump to the first tag that matches {keyword}
:tjump {keyword} Prompt user to select from multiple matches for {keyword}. If only one match exists, jump to it without prompting
:pop or <C-t> Reverse through tag history
:tag Advance through tag history
:tnext Jump to next matching tag
:tprev Jump to previous matching tag
:tfirst Jump to first matching tag
:tlast Jump to last matching tag
:tselect Prompt user to choose an item from the tag matching list