使用 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 : 连接超时
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 zyj zyj .0K 7月 : .
drwxr-xr-x zyj zyj .0K 7月 : ..
drwxr-xr-x zyj zyj .0K 7月 : BoostParts
-rw-r--r-- zyj zyj 18K 7月 : CMakeCache.txt
drwxr-xr-x zyj zyj .0K 7月 : CMakeFiles
-rw-r--r-- zyj zyj .6K 7月 : cmake_install.cmake
-rw-r--r-- zyj zyj 19K 7月 : compile_commands.json
-rw-r--r-- zyj zyj .1K 7月 : Makefile
drwxr-xr-x zyj zyj .0K 7月 : ycm
2.3 上面 2.2 只是构建了中间编译,下面执行最终编译
# 如果你不是 window 系统,可以将 --config Release 去掉
cmake --build . --target ycm_core --config Release
编译过程如下:
[ %] Building CXX object ycm/CMakeFiles/ycm_core.dir/Candidate.cpp.o
[ %] Building CXX object ycm/CMakeFiles/ycm_core.dir/CandidateRepository.cpp.o
[ %] Building CXX object ycm/CMakeFiles/ycm_core.dir/Character.cpp.o
[ %] Building CXX object ycm/CMakeFiles/ycm_core.dir/CharacterRepository.cpp.o
[ %] Building CXX object ycm/CMakeFiles/ycm_core.dir/ClangCompleter/ClangCompleter.cpp.o
[ %] Building CXX object ycm/CMakeFiles/ycm_core.dir/ClangCompleter/ClangHelpers.cpp.o
[ %] Building CXX object ycm/CMakeFiles/ycm_core.dir/ClangCompleter/ClangUtils.cpp.o
[ %] Building CXX object ycm/CMakeFiles/ycm_core.dir/ClangCompleter/CompilationDatabase.cpp.o
[ %] Building CXX object ycm/CMakeFiles/ycm_core.dir/ClangCompleter/CompletionData.cpp.o
[ %] Building CXX object ycm/CMakeFiles/ycm_core.dir/ClangCompleter/Documentation.cpp.o
[ %] Building CXX object ycm/CMakeFiles/ycm_core.dir/ClangCompleter/Range.cpp.o
[ %] Building CXX object ycm/CMakeFiles/ycm_core.dir/ClangCompleter/TranslationUnit.cpp.o
[ %] Building CXX object ycm/CMakeFiles/ycm_core.dir/ClangCompleter/TranslationUnitStore.cpp.o
[ %] Building CXX object ycm/CMakeFiles/ycm_core.dir/CodePoint.cpp.o
[ %] Building CXX object ycm/CMakeFiles/ycm_core.dir/CodePointRepository.cpp.o
[ %] Building CXX object ycm/CMakeFiles/ycm_core.dir/IdentifierCompleter.cpp.o
[ %] Building CXX object ycm/CMakeFiles/ycm_core.dir/IdentifierDatabase.cpp.o
[ %] Building CXX object ycm/CMakeFiles/ycm_core.dir/IdentifierUtils.cpp.o
[ %] Building CXX object ycm/CMakeFiles/ycm_core.dir/PythonSupport.cpp.o
[ %] Building CXX object ycm/CMakeFiles/ycm_core.dir/Result.cpp.o
[ %] Building CXX object ycm/CMakeFiles/ycm_core.dir/Utils.cpp.o
[ %] Building CXX object ycm/CMakeFiles/ycm_core.dir/Word.cpp.o
[ %] Building CXX object ycm/CMakeFiles/ycm_core.dir/versioning.cpp.o
[ %] Building CXX object ycm/CMakeFiles/ycm_core.dir/ycm_core.cpp.o
[%] Linking CXX shared library /home/zyj/.vim/bundle/YouCompleteMe/third_party/ycmd/ycm_core.so
[%] 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.+ or 3.4+) support.
YouCompleteMe unavailable: unable to load Python.
在 YouComplate 的 github issue 上找到了解决方法,原理我也不知道
sudo apt install vim-gtk
随后就好了,再次进入编辑没有报错提示,YCM 也正常生效了
现在,愉快的开始你的代码吧!