限制Vim自动补全仅搜索当前文件?

5

ctrl+nctrl+p 是 Vim 非常方便的自动补全功能,但有时它非常缓慢,可能是因为当前源文件中包含了太多的头文件。是否有一种选项可以限制自动补全仅在当前源文件(或已打开的流)中搜索?

3个回答

10

您需要尝试使用complete选项。

根据帮助文件,

The default is ".,w,b,u,t,i", which means to scan:
   1. the current buffer
   2. buffers in other windows
   3. other loaded buffers
   4. unloaded buffers
   5. tags
   6. included files

个人而言,我注意到删除包含文件非常有帮助,因此在我的 .vimrc 文件中,我使用如下代码:

set complete-=i

但您也可以删除(或添加)其他列表。
有关更多信息,请参见:help 'complete'

5
如果您有一种感觉,能够知道何时出现“有时候”(大型项目、包含多个文件的复杂C文件等),您也可以使用 <C-x><C-n> 本地文件补全功能,参见 :help i_CTRL-X_CTRL-N。这样,您仍然可以使用默认的补全功能,而不需要修改 'complete' 选项。

非常棒且灵活的解决方案。谢谢。 - Marcin Rogacki

2

:help i_ctrl-n 表示:

Find next match for words that start with the
keyword in front of the cursor, looking in places
specified with the 'complete' option. The found
keyword is inserted in front of the cursor.

下一步相当明显,不是吗?

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