Vim插件YouCompleteMe安装记录(号称最难装的Vim插件?)
使用 PulginInstall 安装就不要想了,如果你没有梯子的话
自己的 ssr 被封,使用的同事的 ss,但是同事设置的加密方式在 linux 上的 ss 应用不支持...
好吧,直接上过程
1. 首先先获取 YouCompleteMe 的代码
cd ~/.vim/bundle # 拉取 YouCompleteMe 项目代码 git clone https://github.com/ycm-core/YouCompleteMe.git # 进入目录 cd YouCompleteMe # 安装子模块 git submodule update --init --recursive
这里安装子模块会出现
fatal: unable to access 'https://go.googlesource.com/tools/': Failed to connect to go.googlesource.com port 443: 连接超时 fatal: 无法克隆 'https://go.googlesource.com/tools' 到子模组路径 '/home/zyj/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/go/src/golang.org/x/tools'
原因 go.googlesource.com 域名国内无法直接访问,这时候根据 后面的路径 /home/zyj/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/go/src/golang.org/x/tools 来知道该模块是要放这个路径下的
到 github 上找到该模块下载到该路径
cd ~/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/go/src/golang.org/x git clone https://github.com/golang/tools.git
回到 YouComplateMe 目录继续安装其他子模块
cd ~/.vim/bundle/YouCompleteMe
# 继续子模块的安装
git submodule update --init --recursive
2. 去一个你喜欢的目录,例如用户主目录
cd ~ # 创建一个目录用来存放接下来要编译的代码的目录 mkdir ~/.ycm_build # 进入目录 cd ~/.ycm_build # 编译输出到当前目录(.ycm_build) cmake -G "Unix Makefiles" . ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp
2.1 如果需要实用 C 语言家族的相关功能(我这里系统自带 llvm 3.8、clang 3.8、libclang 没有、libboost-all-dev 没有),不需要则直接跳过 2.1
sudo apt install llvm-3.9 clang-3.9 libclang-3.9-dev libboost-all-dev
2.2 编译 YouComplateMe
# 跳过了 2.1 执行
cmake -G "Unix Makefiles" . ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp
# 执行了 2.1 请执行
cmake -G "Unix Makefiles" -DUSE_SYSTEM_BOOST=ON -DUSE_SYSTEM_LIBCLANG=ON . ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp
可以看到 ~/.ycm_build 目录下结构( 我没有跳过 2.1,如果你跳过了说不定有不一样的,只要编译过程中没有报错就没有问题 )
# zsh 下 l 等于 bash 下的 ls -al
l ~/.ycm_build 总用量 72K drwxr-xr-x 5 zyj zyj 4.0K 7月 18 19:00 . drwxr-xr-x 46 zyj zyj 4.0K 7月 18 19:35 .. drwxr-xr-x 3 zyj zyj 4.0K 7月 18 19:00 BoostParts -rw-r--r-- 1 zyj zyj 18K 7月 18 19:00 CMakeCache.txt drwxr-xr-x 4 zyj zyj 4.0K 7月 18 19:03 CMakeFiles -rw-r--r-- 1 zyj zyj 1.6K 7月 18 19:00 cmake_install.cmake -rw-r--r-- 1 zyj zyj 19K 7月 18 19:00 compile_commands.json -rw-r--r-- 1 zyj zyj 4.1K 7月 18 19:00 Makefile drwxr-xr-x 3 zyj zyj 4.0K 7月 18 19:00 ycm
2.3 上面 2.2 只是构建了中间编译,下面执行最终编译
# 如果你不是 window 系统,可以将 --config Release 去掉
cmake --build . --target ycm_core --config Release
编译过程如下:
[ 4%] Building CXX object ycm/CMakeFiles/ycm_core.dir/Candidate.cpp.o [ 8%] Building CXX object ycm/CMakeFiles/ycm_core.dir/CandidateRepository.cpp.o [ 12%] Building CXX object ycm/CMakeFiles/ycm_core.dir/Character.cpp.o [ 16%] Building CXX object ycm/CMakeFiles/ycm_core.dir/CharacterRepository.cpp.o [ 20%] Building CXX object ycm/CMakeFiles/ycm_core.dir/ClangCompleter/ClangCompleter.cpp.o [ 24%] Building CXX object ycm/CMakeFiles/ycm_core.dir/ClangCompleter/ClangHelpers.cpp.o [ 28%] Building CXX object ycm/CMakeFiles/ycm_core.dir/ClangCompleter/ClangUtils.cpp.o [ 32%] Building CXX object ycm/CMakeFiles/ycm_core.dir/ClangCompleter/CompilationDatabase.cpp.o [ 36%] Building CXX object ycm/CMakeFiles/ycm_core.dir/ClangCompleter/CompletionData.cpp.o [ 40%] Building CXX object ycm/CMakeFiles/ycm_core.dir/ClangCompleter/Documentation.cpp.o [ 44%] Building CXX object ycm/CMakeFiles/ycm_core.dir/ClangCompleter/Range.cpp.o [ 48%] Building CXX object ycm/CMakeFiles/ycm_core.dir/ClangCompleter/TranslationUnit.cpp.o [ 52%] Building CXX object ycm/CMakeFiles/ycm_core.dir/ClangCompleter/TranslationUnitStore.cpp.o [ 56%] Building CXX object ycm/CMakeFiles/ycm_core.dir/CodePoint.cpp.o [ 60%] Building CXX object ycm/CMakeFiles/ycm_core.dir/CodePointRepository.cpp.o [ 64%] Building CXX object ycm/CMakeFiles/ycm_core.dir/IdentifierCompleter.cpp.o [ 68%] Building CXX object ycm/CMakeFiles/ycm_core.dir/IdentifierDatabase.cpp.o [ 72%] Building CXX object ycm/CMakeFiles/ycm_core.dir/IdentifierUtils.cpp.o [ 76%] Building CXX object ycm/CMakeFiles/ycm_core.dir/PythonSupport.cpp.o [ 80%] Building CXX object ycm/CMakeFiles/ycm_core.dir/Result.cpp.o [ 84%] Building CXX object ycm/CMakeFiles/ycm_core.dir/Utils.cpp.o [ 88%] Building CXX object ycm/CMakeFiles/ycm_core.dir/Word.cpp.o [ 92%] Building CXX object ycm/CMakeFiles/ycm_core.dir/versioning.cpp.o [ 96%] Building CXX object ycm/CMakeFiles/ycm_core.dir/ycm_core.cpp.o [100%] Linking CXX shared library /home/zyj/.vim/bundle/YouCompleteMe/third_party/ycmd/ycm_core.so [100%] Built target ycm_core
随后讲编译后文件放到你想要放入的目录
cp ~/.vim/bundle/YouCompleteMe/third_party/ycmd/examples/.ycm_extra_conf.py ~/.vim/
随后在将 python 和 写入到 ~/.vimrc 中,在文件中位置你随意就好
let g:ycm_server_python_interpreter='/usr/bin/python' let g:ycm_global_ycm_extra_conf='~/.vim/.ycm_extra_conf.py'
然后尝试写个文件吧
vim hello.c # 报了如下错误,但是按任意键后依然进入编辑器了,但是 ycm 并不生效 YouCompleteMe unavailable: requires Vim compiled with Python (2.7.1+ or 3.4+) support. YouCompleteMe unavailable: unable to load Python.
在 YouComplate 的 github issue 上找到了解决方法,原理我也不知道
sudo apt install vim-gtk
随后就好了,再次进入编辑没有报错提示,YCM 也正常生效了
现在,愉快的开始你的代码吧!
参考:https://www.jianshu.com/p/d908ce81017a?nomobile=yes