How do I view the first macro or keyword definition without leaving my current position?
Answer
[d
Explanation
The [d command searches from the beginning of the file for the first line matching the define pattern for the word under the cursor, and displays it in the status bar — all without moving your cursor. It's a quick way to inspect a macro value or constant definition while keeping your place in the code.
How it works
[d— searches from the start of the file and displays the first definition of the keyword under the cursor]d— searches from the cursor forward to find the next definition[D— lists all matching definitions in the file (like:dlist /word/)[<C-D>— actually jumps to the first definition (vs. just displaying it)- Vim uses the
defineoption pattern to identify definition lines (default:^\s*#\s*definefor C preprocessor macros)
Example
#define MAX_RETRIES 5
...
if (retries > MAX_RETRIES) { ← cursor here
With the cursor on MAX_RETRIES, pressing [d shows in the status bar:
1 #define MAX_RETRIES 5
Tips
- For non-C languages, customize the search:
:set define=^\s*const\sfor JavaScript/TypeScript constants - Use
[Dwhen you want to see all occurrences at once (for example, when a symbol is defined in multiple#ifdefbranches) - Once you've seen the definition with
[d, use[<C-D>to actually navigate there