C++ Vim YouCompleteMe 配置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16264047/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 20:11:26  来源:igfitidea点击:

Vim YouCompleteMe configuration

c++vimautocomplete

提问by mastergap

i just installed YouCompleteMe for Vim through vundle. It works, but it shows only the words contained in the current file. I want to use it to develop c++ programs, how can i configure it to show autocompletion from c++ headers file in /usr/include for example? Thanks a lot.

我刚刚通过 vundle 为 Vim 安装了 YouCompleteMe。它有效,但它只显示当前文件中包含的单词。我想用它来开发 c++ 程序,例如,我如何配置它以显示 /usr/include 中 c++ 头文件的自动完成?非常感谢。

采纳答案by xoSauce

While the suggestions here might work in the beginning, I am not sure it's the proper way to go. According to YCM developer, whenever you start a project, you need a new .ycm_extra_conf.pyfile

虽然这里的建议在一开始可能会奏效,但我不确定这是正确的方法。根据 YCM 开发人员的说法,每当您开始一个项目时,您都需要一个新的.ycm_extra_conf.py文件

From https://valloric.github.io/YouCompleteMe/#ubuntu-linux-x64-super-quick-installation

来自https://valloric.github.io/YouCompleteMe/#ubuntu-linux-x64-super-quick-installation

YCM looks for a .ycm_extra_conf.py file in the directory of the opened file or in any directory above it in the hierarchy (recursively); when the file is found, it is loaded (only once!) as a Python module. YCM calls a FlagsForFile method in that module which should provide it with the information necessary to compile the current file. You can also provide a path to a global .ycm_extra_conf.py file, which will be used as a fallback. To prevent the execution of malicious code from a file you didn't write YCM will ask you once per .ycm_extra_conf.py if it is safe to load. This can be disabled and you can white-/blacklist files. See the Options section for more details.

YCM 在打开的文件所在的目录或层次结构中位于它上面的任何目录中(递归地)查找 .ycm_extra_conf.py 文件;找到文件后,它会作为 Python 模块加载(仅一次!)。YCM 在该模块中调用 FlagsForFile 方法,该方法应为其提供编译当前文件所需的信息。您还可以提供全局 .ycm_extra_conf.py 文件的路径,该文件将用作后备。为了防止从您没有编写的文件中执行恶意代码,YCM 会在每个 .ycm_extra_conf.py 中询问您是否可以安全加载。这可以禁用,您可以将文件列入白名单/黑名单。有关更多详细信息,请参阅选项部分。

While you might only need to modify the compile flags from the vanilla .ycm_extra_conf.py, I feel it is advisable to create a new file for every project you start.

虽然您可能只需要修改 vanilla .ycm_extra_conf.py 中的编译标志,但我认为建议为您开始的每个项目创建一个新文件。

回答by Battleroid

You need to navigate to ~/.vim/bundles/YouCompleteMeand run the installation script with --clang-completer, so do ./install.sh --clang-completer. After it finishes you should have support for C like languages.

您需要使用 导航到~/.vim/bundles/YouCompleteMe并运行安装脚本--clang-completer,所以这样做./install.sh --clang-completer。完成后,您应该支持类似 C 的语言。

You may also need to place let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py'in your ~/.vimrc.

您可能还需要地方let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py'在你的~/.vimrc

回答by deph

I have installed with pathogen. I tried the above instructions with ./install.sh --clang-complete. After this, it did not work, and I indeed had to add the path. But it was different than in another reply here, namely

我已经安装了病原体。我使用 ./install.sh --clang-complete 尝试了上述说明。在此之后,它不起作用,我确实不得不添加路径。但这与这里的另一个回复不同,即

let g:ycm_global_ycm_extra_conf = '.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'

so there is an extra "third_party/ycmd" in the path.

所以路径中有一个额外的“third_party/ycmd”。

回答by Kourosh Taheri-Golvarzi

Everything that the folks here have said is correct. I just want to add that as of 2017, the "install.sh" script is deprecated. Now, you have to use the install.py script instead by typing

这里的人说的都是对的。我只想补充一点,截至 2017 年,“install.sh”脚本已被弃用。现在,您必须通过键入来使用 install.py 脚本

./install.py --clang-completer

Also, in your .vimrc file, instead of ".vim/bundle/blahblahblah", you'll need to add a "~/" in front of the address by adding:

此外,在您的 .vimrc 文件中,您需要在地址前添加一个“~/”,而不是“.vim/bundle/blahblahblah”,添加:

let g:ycm_global_ycm_extra_conf = "~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py"

to your .vimrc file, to give it an absolute path from the Home directory so that Vim can find the ".ycm_extra_conf.py" file. Otherwise, you might experience some funny behavior.

到你的 .vimrc 文件,给它一个来自 Home 目录的绝对路径,以便 Vim 可以找到“.ycm_extra_conf.py”文件。否则,您可能会遇到一些有趣的行为。

回答by user2267258

I just wanted to add if you don't want to manually define a config file there is this neat little repository that will auto generate it. https://github.com/rdnetto/YCM-Generator

我只是想补充一下,如果您不想手动定义配置文件,那么有这个整洁的小存储库可以自动生成它。https://github.com/rdnetto/YCM-Generator