3

From the help:

                             i_CTRL-X_CTRL-I
CTRL-X CTRL-I           Search for the first keyword in the current and
                        included files

From Tim Pope's Gitub:

[i: display the first line in the current file or an included file containing the keyword under the cursor.

But I'm struggling to find a definition, or examples, of what includes files are.

So, where is the vim reference for included files? I'd like to be able to list them, add to them, that sort of thing.

I think that vim scans a file for lines that match the 'include' search pattern, put them through the 'includexpr' conversion and stores those files someone, to be used in other commands, but I can't even find a list of commands that aren't the ones listed above...

1
  • 1
    Think “include” in C, import in many other languages – D. Ben Knoble May 2 '20 at 12:10
6

First I did a :helpgrep included files, then went through the most promising matches until I found:

From :help included-search:

6. Include file searches        *include-search* *definition-search*
                            *E387* *E388* *E389*

These commands look for a string in the current file and in all encountered
included files (recursively).  This can be used to find the definition of a
variable, function or macro.  If you only want to search in the current
buffer, use the commands listed at |pattern-searches|.

These commands are not available when the |+find_in_path| feature was disabled
at compile time.

When a line is encountered that includes another file, that file is searched
before continuing in the current buffer.  Files included by included files are
also searched.  When an include file could not be found it is silently
ignored.  Use the |:checkpath| command to discover which files could not be
found, possibly your 'path' option is not set up correctly.  Note: the
included file is searched, not a buffer that may be editing that file.  Only
for the current file the lines in the buffer are used.

The string can be any keyword or a defined macro.  For the keyword any match
will be found.  For defined macros only lines that match with the 'define'
option will be found.  The default is "^#\s*define", which is for C programs.
For other languages you probably want to change this.  See 'define' for an
example for C++.  The string cannot contain an end-of-line, only matches
within a line are found.

When a match is found for a defined macro, the displaying of lines continues
with the next line when a line ends in a backslash.

The commands that start with "[" start searching from the start of the current
file.  The commands that start with "]" start at the current cursor position.

The 'include' option is used to define a line that includes another file.  The
default is "\^#\s*include", which is for C programs.  Note: Vim does not
recognize C syntax, if the 'include' option matches a line inside
"#ifdef/#endif" or inside a comment, it is searched anyway.  The 'isfname'
option is used to recognize the file name that comes after the matched
pattern.

Seems to be related to c file include styles, but can be customised.

Extra side note:

When looking up a term in the help, one has auto completion (like command line completion). Try add this to you init.vim:

set wildmenu
set wildmode=longest,list:full

Then type: :h cmdline-c then type <TAB> or CTRL-d to select cmdline-completion. Note: :h is short for :help

2
  • 1
    It's been used well for js, python, java, scala, etc. if things are setup right – D. Ben Knoble May 2 '20 at 14:47
  • 1
    Thank you! TIL about helpgrep as well. – Joe May 2 '20 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.