Vim Tips Wiki
Tip 9 Printable Monobook Previous Next

created 2001 · complexity basic · author Yegappan · version 5.7

To display the definition of a variable, place the cursor on the variable and use the [i command.

To display a macro definition, place the cursor on the macro name and use the [d command.

To display all the lines containing the variable name under the cursor, use the [I command.

These commands work by literally searching for the text. So they work in most, but not all, cases.

List lines in this file, and in included files, containing keyword under cursor.
The meaning of included depends on settings, but defaults are set for C (with search of directories normally used for #include).
Jump to first match (first line in file containing keyword).
Ctrl-i is Tab, so, [<Tab> also jumps to the first match.
Jump to next match (first line after cursor containing keyword).
This follows the <C-i>/<C-o> jumping patterns.
Prepend the windowing operator (Ctrl-w) to open in a new window.
Go to definition of local variable (first occurrence of keyword in current function).
Go to definition of global variable (first occurrence of keyword in current file).

See also[]


Search in files[]

Use :grep or :vimgrep to search for a pattern in files. See Find in files within Vim.

" grep for word under cursor in c/cpp/h-files
nnoremap <F9> <Esc>:exec("grep ".expand("<cword>")." ../*/*.c* ../*/*.h")<CR>

You can omit <CR> for manual changing the file pattern before searching.

If you have configured set grepprg=mygrep\ -n then you can use quickfix mode for jumping to the found locations.



  • Have merged information from other tips to here. See if any more cleaning up is required.
  • Confirm that descriptions (drastically simplified wrt help) are accurate.
  • Possibly make the "Search in files" section just a line under "See also". Is the 'nnoremap <F9>' stuff useful?