Vim Recall繁體中文

Find a local declaration

gd

Example

Normal 0 / 1
int count;
void example() {
  int count;
  count = 2;
}
Cursor on line 4, column 3

Search for a local declaration of the cursor word.

Before & after
Before
int count;
void example() {
  int count;
  count = 2;
}
Cursor on line 4, column 3
After
int count;
void example() {
  int count;
  count = 2;
}
Cursor on line 1, column 5

Start in Normal mode. The opening brace is not in column 1, so gd does not recognize a function start and searches from line 1, finding the global count rather than the nearer local declaration.

Details & Vim help

Example replayed in Vim

Search for a local declaration of the cursor word.

gd searches for the word under the cursor from the start of the current function. Vim identifies a function by an opening brace in column 1. This example puts the brace at the end of a line, so Vim starts at line 1 and finds the global declaration.