How do I view all the files Vim would search when resolving include-based completions and lookups?
Answer
:checkpath!
Explanation
:checkpath! recursively walks through every file reachable via Vim's include path and displays the full include tree. This reveals exactly which files Vim will search when you use include-aware commands like [i, [d, ]i, and insert-mode <C-x><C-i> completion.
How it works
:checkpath(no!) shows only files that cannot be found — it lists broken includes:checkpath!shows all included files, found or missing, with their nesting depth shown by indentation- Vim determines includes using
:set include(the pattern to match include statements) and:set path(directories to search) - For C/C++, Vim defaults match
#includedirectives; for other languages, set:set includeappropriately
Example
In a C file:
:checkpath!
Typical output:
/usr/include/stdio.h
/usr/include/bits/types.h
/usr/include/bits/wordsize.h
/usr/include/string.h
Indentation indicates nesting. This tells you which headers are available for [i symbol lookup and <C-x><C-i> completion.
Tips
- Once you know the include tree,
[ishows the first occurrence of the word under cursor across all included files [Ilists all occurrences (with line numbers) across all included files[dand[Ddo the same for macro/#definelookups- Expand the search with
:set path+=.,src/**to include project directories - For non-C languages, configure
:set include=and:set includeexpr=to teach Vim how to find imports