How do I list all lines matching a pattern across the current file and its includes?
Answer
:ilist /pattern/
Explanation
The :ilist command searches for a pattern not only in the current buffer but also in files referenced by #include directives (or whatever 'include' is set to). It displays every matching line with its file name and line number, giving you a quick overview of all occurrences across related files.
How it works
:ilist /pattern/searches the current file and any included files for lines matching the pattern, then displays them in a numbered list:ilist wordsearches for the literal keywordwordinstead of a regex pattern- Each result shows the file path, line number, and the matching line content
- After seeing the list, use
:ijump N /pattern/to jump directly to the Nth match - The simpler form
[Iin normal mode lists all lines in the current file and includes that contain the word under the cursor
Example
:ilist /TODO/
1: 5 src/main.c: // TODO: refactor this function
2: 12 src/utils.h: // TODO: add error handling
3: 28 src/main.c: // TODO: optimize loop
Jump to the 2nd match:
:ijump 2 /TODO/
Tips
- Use
[Ias a quick normal-mode shortcut to list all occurrences of the word under the cursor - Pair with
[ito show just the first match, or]ifor the next match after the cursor - The
'include'and'path'options control which files Vim searches — customize them for your project's include conventions