Is there a plugin which autocompletes C/C++ code from specific headers given in a specific path (i.e.
If I include some headers from that path, I would get autocompletion from given header.
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.Sign up to join this community
'path' to include the path to your include files. In your example:
Vim native completion is quite useful for C and C++ files, Vim can search for your include files and find candidate completion targets in them and the defaults in Vim are already pretty useful for Vim completion.
You can use the
CTRL-X CTRL-I sequence to initiate keyword completion, completing keywords in the current and include files.
CTRL-X CTRL-D to initiate define completion, completing macros and defines in the current and include files.
The important option to customize for these is
'path', which tells Vim where to search for include files.
By default, Vim will search the directory where the file lives (if you're editing
src/submodule/xyz.c, then it will search under
src/submodule first), the system include directory (
/usr/include) and the current directory (which might typically be the root of your project.)
You might want to add paths to this setting, basically any include path you're passing the compiler through a
-I flag should be of interest here.
'includeexpr', which can be used to translate an include to a file name (useful for languages in which submodule paths are separated by
. rather than
These are already correctly set for C/C++ by default, so you typically don't need to set these unless you're working with a different language.
There are other commands that can become very useful once
'path' is set correctly to find your include files.
For instance, see include file search for commands such as
[d which will show you the first occurrence of a keyword (or a define) and will go inside include files whenever it sees an
#include directive. This can be quite powerful, as a quick way to check a function prototype wherever it's declared.