仓库地址 https://github.com/ycm-core/YouCompleteMe
安装编译环境:
sudo apt install build-essential cmake
sudo apt install python-dev python3-dev
sudo apt install ctags
sudo apt install gcc g++
sudo apt install clang libclang-dev
git clone https://github.com/ycm-core/YouCompleteMe.git ~/.vim/bundle/YouCompleteMe
Compiling YCM with semantic support for C-family languages through libclang:
cd ~/.vim/bundle/YouCompleteMe
python3 install.py --clang-completer
到这里会提示 "git submodule update --init --recursive"
继续
sudo 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'
处理:https://www.cnblogs.com/YMaster/p/11209813.html
原因 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
cd ~/.vim/bundle/YouCompleteMe
# 继续子模块的安装
git submodule update --init --recursive
成功安装子模块。
cd ~/.vim/bundle/YouCompleteMe
python3 install.py --clang-completer
Done.
-----------------------------------以下为配置-----------------------------------------
cp ~/.vim/bundle/YouCompleteMe/third_party/ycmd/examples/.ycm_extra_conf.py ~/.vim/
在~/.vimrc中添加
let g:ycm_server_python_interpreter='/usr/bin/python3'
let g:ycm_global_ycm_extra_conf='~/.vim/.ycm_extra_conf.py'
在~/.vimrc总 call vundle#begin() 和 call vundle#end() 之间添加插件
Plugin 'Valloric/YouCompleteMe'
莫要忘记在vim中安装插件
vim 任意文件,进入命令模式
至此自动补全功能阔以用了。
上图
--------------------------------------------------------------------------------------------------------------------------------------
使用YCM的跳转功能
在~/.vimrc中添加
nnoremap jd :YcmCompleter GoToDefinitionElseDeclaration<CR>
nnoremap <F2> :YcmCompleter GoToDefinitionElseDeclaration<CR>
“使用',j+d'组合键/F2键 完成跳转,跳转到函数或变量的声明或定义位置
跳转成功之后,可使用VIM命令ctrl+o返回光标上一个位置
配合ctags 一起使用,更舒服(函数跳转)
vimrc上传还要写50个字的概述...
参考:https://blog.youkuaiyun.com/liao20081228/article/details/80347889
------------------------------End