当前位置: 首页 > 工具软件 > YouCompleteMe > 使用案例 >

windows 10 平台安装 vim 插件 YouCompleteMe 详细流程

柳修平
2023-12-01

配置流程

0. 编译和安装环境

  1. Visual Studio Build Tools 2019 (或直接安装 VS2019)
  2. CMake
  3. Python (作者安装时使用的是 Python3)
  4. vim

1. 配置 vim 的 Python 路径

在设置配置文件前, 请确保以下命令的输出为 1 .

:echo has("python_dynamic")

以及

:echo has("python3_dynamic")

_vimrc (或 .vimrc ) 中添加如下语句

" Python3
set pythonthreehome=D:\Python3.7.3
set pythonthreedll=D:\Python3.7.3\python37.dll

如果你使用的是 Python2 , 添加如下语句.

" Python2
set pythonhome=D:\Python2
set pythondll=D:\Python2\python27.dll

配置完成后, 重新加载 vimrc , 使用以下命令来检查输出是否正确

:py3 print("test")

Python2

:py print "test"

2. 安装 vim-plug

项目主页 上下载 plug.vim 文件, 然后将其添加在 vim82\autoload 文件下.

3. 设置代理[可选]

若在 vim-plug 下载过程出现超时以及 SSL 错误, 可在给设置 git bash 代理后, 手动 git clone 项目到插件文件夹中. 注意, git bash 的代理设置是全局的, 也就是设置代理并关闭窗口后, 下一次打开窗口仍然会保留上次的代理设置.

设置代理

git config --global http.proxy http://127.0.0.1:1081
git config --global https.proxy http://127.0.0.1:1081

查看代理

git config http.proxy
git config https.proxy

取消代理

git config --unset http.proxy
git config --unset https.proxy

若在 cmake 的编译过程中, 下载依赖时出现下载超时以及 SSL 错误, 可在 CMD 窗口中设置代理后重新进行编译. CMD 的代理设置是针对于窗口的, 多个窗口间不会相互影响.

设置代理

set http_proxy=http://127.0.0.1:1081
set https_proxy=http://127.0.0.1:1081

查看代理

set http_proxy
set https_proxy

4. 使用 vim-plug 下载 YouCompleteMe

_vimrc (或 .vimrc ) 文件中添加如下内容

call plug#begin('./plugs')
Plug 'ycm-core/YouCompleteMe'
call plug#end()

其中 ./plugs 为插件的目录, ycm-core/YouCompleteMe 为项目的地址.

添加完毕后, 重启 vim 或重新载入配置文件, 输入以下命令以下载 YouCompleteMe

:PlugInstall

5. 编译 YouCompleteMe

打开 CMD , 移动到 ./vim82/plugs/YouCompleteMe 目录, 输入以下命令来编译 YouCompleteMe

python3 install.py

上述命令仅编译了 YouCompleteMe , 并没有添加相应的语言支持. 若要添加相应的语言支持, 确保正确配置了相应语言环境的同时, 在编译命令中加入以下参数

  • C-family languages: --clangd-completer
  • C# support: install Mono and add --cs-completer when calling ./install.py.
  • Go support: install Go and add --go-completer when calling ./install.py.
  • JavaScript and TypeScript support: install Node.js and npm and add --ts-completer when calling install.py.
  • Rust support: add --rust-completer when calling ./install.py.
  • Java support: install JDK8 (version 8 required) and add --java-completer when calling ./install.py.

举个例子, 添加 C 语言系列支持:

python3 install.py --clangd-completer

如果要添加所有的语言支持, 可输入以下命令

python3 install.py --all

6. 检查安装是否成功

打开 vim , 输入命令

:scriptnames

youcompleteme.vim 包含在加载列表中, 则表明安装成功.


参考

 类似资料: