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

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 #include directives; for other languages, set :set include appropriately

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, [i shows the first occurrence of the word under cursor across all included files
  • [I lists all occurrences (with line numbers) across all included files
  • [d and [D do the same for macro/#define lookups
  • 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

Next

How do I encode and decode JSON data in Vimscript for configuration and plugin development?