Jagi125 Jagi125 - 1 month ago 10
C Question

Vim autocompletion from library included in another file

I use Fedora 24. I write Ansi C programs in Vim, using it's native autocompletion under ^N. And everything works fine until I define library in another file like this:

fileA.c

#include <allegro5/allegro.h>
#include "fileB.c"


fileB.c

...


If I try to autocomplete in fileA.c it looks up in both file b and library.
But in file a it searches only in fileA.c. How can I look up for library's functions and constants in fileB.c?

Answer

When you are in fileA.c, completions are pulled (among other places) from all includes in that file and includes in those includes, recursively.

This happens because the default value of 'complete' contains i.

When you are in fileB.c, completions can't be pulled from any include because you don't seem to have any but they can still be pulled from the current buffer (. in complete), other buffers (w, b, u), and even tags files (t).

That said, explicitly including a resource is necessary in C if you want to use it so I'm not sure it is wise to expect any resource to be available in your code without proper includes.

Comments