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

How do I quickly see where a keyword was first defined or used without jumping there?

Answer

[i

Explanation

Pressing [i in normal mode displays the first line above the cursor (including included files) that contains the keyword under the cursor. The match is shown in the status line without moving the cursor, making it a zero-friction way to peek at a variable's type, function signature, or macro definition.

How it works

Vim's [{char} family of commands searches upward from the cursor through the current file and any files pulled in via #include (or path-based includes). i stands for the "include" search:

  • [i — display the first matching line above the cursor
  • [I — list all matching lines above the cursor with line numbers
  • [<C-i>jump to the first match above the cursor
  • ]i — same as [i but searches downward

The search uses the same keyword definition as * (respecting iskeyword), so it matches whole words only.

Example

With the cursor on MAX_RETRIES:

1: #define MAX_RETRIES 5
...
47: if (attempts > MAX_RETRIES) {   ← cursor here

Pressing [i shows in the status bar:

   1: #define MAX_RETRIES 5

Tips

  • Use [I instead of [i when you want to scan all occurrences: each match is numbered so you can jump to any entry with N[<C-i>.
  • Works through #include chains when path is configured — useful for reading C/C++ codebases.
  • Complement with gd (go to local declaration) and gD (go to global declaration) for quick navigation without LSP.

Next

How do I exclude compiled files and dependency folders from Vim's file name completion?