tags:

views:

713

answers:

3

How do i tell vim editor about my include files path, so that it can auto complete the function names when i press control+N.

For example, I have c program like below

#include<stdio.h>
int main()
{
    sca //here i press control+N, it doesnot complete to scanf
}
+9  A: 

In your .vimrc add the paths to your .vimrc

set path+=/usr/include/**
set path+=/my_include_dir/include
set path+=/my_include_dir/srclib/apr/**
set path+=/my_other_include_dir/srclib/apr-util/**

** means all sub-directories.
*  means all contained directories
.  means all files in the directory of the found file
+= means prepend to existing path (iirc)

You can check the paths as well by opening your file and then entering

:checkpath

This will give you a list of all included files that are missing. N.B. It doesn't seem to handle preprocessor directives, so you will get some false positives. Entering

:checkpath!

Will give a complete list of found and missing include files.

HTH

cheers,

Rob

Rob Wells
+9  A: 

Also, Important to note there are many completion functions.

^x ^o  = "omnicomplete" 
^x ^i  = "included-files completion" 
^x ^f  = "path completion" 
^x ^l  = "Complete this line using one that looks the same"

see

:help ins-completion

for more.

Kent Fredric
+1  A: 

Vim might also know the path already, if the files are in a standard location. <C-n> uses the 'complete' option and the flag i scans included files. To add i to 'complete':

set complete+=i

you can also get a tags file from the symbols you want completed, which you can use with:

set complete+=t

Heikki Naski