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

How do I jump to a definition-style pattern match using Vim's define search?

Answer

:djump /MY_MACRO/

Explanation

:djump searches for matches using Vim's definition search rules and jumps to the selected hit. It is designed for definition-like navigation, so it works best when your define option reflects the language forms you care about (functions, macros, constants, etc.). This gives you a lightweight navigation path when tags are missing or incomplete.

How it works

  • :djump /MY_MACRO/ scans the current file and related include targets for definition matches
  • Matching uses your current define, include, and path options
  • Vim presents candidates and jumps directly to the chosen location

This can be faster than broad grep when your project has a predictable declaration style and include graph.

Example

:set define=^\s*#\s*define
:set path+=include/**
:djump /MAX_BUFFER/

With those settings, :djump focuses on C-style macro definitions and jumps to the declaration you select.

Tips

  • Pair :dlist /pattern/ with :djump /pattern/ when you want to preview before jumping
  • Tune define per filetype using autocmd FileType for better accuracy
  • Use tags for primary navigation and :djump as a robust fallback when tags are stale

Next

How do I clear undo history for the current buffer in Vim?