Vim 关键字自动补全

12

如何告诉 Vim 编辑器我的包含文件路径,以便在我按下 CTRL+N 时它能自动完成函数名呢?

例如,我有一个像下面这样的 C 程序:

#include<stdio.h>
int main()
{
    sca // here I press control+N, it does not complete to scanf
}
3个回答

21
在你的.vimrc文件中,添加路径到你的.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)
您可以通过打开文件并输入命令来检查路径。
:checkpath
这将会给你一个所有缺失文件的列表。需要注意的是,它似乎无法处理预处理指令,所以你可能会得到一些错误的结果。输入
:checkpath!

将提供一个完整的已找到和缺失的包含文件列表。


16

需要注意的是,有许多补全函数可用。

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

了解更多信息。


3

如果文件在标准位置,Vim可能已经知道路径。使用<C-n>时会使用'complete'选项和标志i扫描包含的文件。要将i添加到'complete'中:

set complete+=i

您还可以从要完成的符号获取标签文件,并将其与以下内容一起使用:

set complete+=t


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接