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

How do I search for tag definitions using a regex pattern instead of an exact name?

Answer

:tag /pattern

Explanation

When working with ctags, you typically jump to exact tag names with <C-]>. But when you only remember part of a function or class name, :tag /pattern lets you search all tags using a regex pattern. This turns Vim's tag system into a powerful code navigation tool — you can find any symbol by partial name, prefix, suffix, or pattern.

How it works

  • :tag — the Ex command to jump to a tag
  • /pattern — the leading / tells Vim to treat the argument as a regex instead of an exact tag name
  • Vim searches the tags file and jumps to the first match

Example

Suppose your project has functions named handleUserLogin, handleUserLogout, handleAdminLogin. To find all handle*Login functions:

:tag /handle.*Login

This jumps to the first match. To see all matches and choose interactively:

:tselect /handle.*Login
  # pri kind tag               file
  1 F   f    handleUserLogin   src/auth.go
  2 F   f    handleAdminLogin  src/admin.go
Type number and <Enter> (empty cancels):

Tips

  • Use :tselect /pattern to see a numbered list of all matches and pick one
  • Use :tjump /pattern to jump directly if there is exactly one match, or show the list if there are multiple
  • The regex follows Vim's pattern syntax, so \< and \> work for word boundaries: :tag /\<get\w*Info\>
  • Requires a tags file generated by ctags or similar tool

Next

How do I ignore whitespace changes when using Vim's diff mode?