Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim Keyword Completion

Tags:

c

vim

How do I tell the Vim editor about my include files path so that it can auto complete the function names when I press CTRL+N?

For example, I have a C program like below:

#include<stdio.h>
int main()
{
    sca // here I press control+N, it does not complete to scanf
}
like image 601
chappar Avatar asked Nov 21 '08 09:11

chappar


2 Answers

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.

like image 167
Kent Fredric Avatar answered Sep 22 '22 03:09

Kent Fredric


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.

like image 28
Rob Wells Avatar answered Sep 24 '22 03:09

Rob Wells