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

How do I jump to the first macro or #define definition of the word under the cursor?

Answer

[<C-d>

Explanation

Vim's [<C-d> command jumps to the first definition of the macro or identifier under the cursor, searching from the beginning of the current file and through any files pulled in via #include (according to the define and include options). Unlike gd which scans for a local variable declaration, [<C-d> is specifically designed for C-style #define macros.

How it works

  • [<C-d> — jump to the first definition matching the word under the cursor
  • ]<C-d> — jump to the next definition after the cursor
  • Vim uses the define option (default: ^\s*#\s*define) to recognize definitions
  • It also searches through files listed in include-scanned paths
  • Related command: [d (without <C-d>) — shows the first definition in the command line without jumping to it

Example

In a C file:

#include "config.h"

void setup() {
    int x = MAX_SIZE;  ← cursor on MAX_SIZE
}

Pressing [<C-d> jumps to the #define MAX_SIZE 256 line, even if it's in config.h.

Tips

  • Use [d first to preview the definition without leaving your current position
  • ]<C-d> moves to the next definition if there are multiple (e.g., conditional defines)
  • The jump is added to the jump list, so <C-o> returns you to where you started
  • Customize which pattern counts as a definition: :set define=...
  • Reference: :help [_CTRL-D

Next

How do I check if a specific Vim feature or capability is available before using it in my vimrc?