入坑vim多天后逐步装插件对vim进行完善,终于今天开始尝试装最牛插件之一YouCompleteMe。一路也是遇到不少问题,甚至想从源码编译,最后发现其实都是些小问题。
本系统为ubuntu
先上插件网址:https://github.com/Valloric/YouCompleteMe
1、
请确保有以下依赖
sudo apt install build-essential cmake python3-dev
2、
这里用的是 vim-plug 下载,用vundle也差不多
call plug#begin('~/.vim/plugged')
Plug 'Valloric/YouCompleteMe', { 'do': './install.py --clang-completer'}
call plug#end()
然后漫长等待至下好,这个时候并不是结束,而是才刚刚开始
3、
cd ~/.vim/plugged/YouCompleteMe/ (就是找到安装目录)
一般这个时候都没有完整克隆下来的,执行命令
git submodule update --init --recursive
好像就可以完整安装下来
4、本文章的重点之一,就是这里开始遇到问题的
在YouCompleteMe目录下运行编译安装
cd ~/.vim/bundle/YouCompleteMe
./install.py --clang-completer
然后就惊奇发现终端有如下回复
CMake Error: The source directory "/home/rivalak/.cache/vimfiles/repos/github.com/Valloric/YouCompleteMe/third_party/ycmd/third_party/cregex" does not appear to contain CMakeLists.txt.
其实这是因为 ~/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/cregex/ 的内部文件没有clone下来
解决方案:rm -rf ~/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/cregex (即删除掉)
再运行git submodule update --init --recursive
然后就可以 ./install.py --clang-completer 成功编译了
5、
然后是问题2:
打开vim,发现YouCompleteme unavailable : no module named future
原因是
~/.vim/plugged/YouCompleteMe/third_party/python-future/ 的内部文件没有clone下来
解决方案:rm -rf ~/.vim/plugged/YouCompleteMe/third_party/python-future/
再运行git submodule update --init --recursive
然后 ./install.py --clang-completer 再编译
6、
然后是问题3:
当你认为终于搞定了高兴的用vim打开.c文件,然后发现
No .ycm_extra_conf.py file detected, so no compile flags are available. Thus no semantic support for C/C++/ObjC/ObjC++. Go READ THE DOCS NOW, DON'T file a bug report.
居然对c和c++不能用!!!
莫方,看英文,是因为找不到.ycm_extra_conf.py 这个文件
所以解决方法上:发现这个文件在 ~/.vim/plugged/YouCompleteMe/third_party/ycmd/examples/ 中,先用命令
mv ~/.vim/plugged/YouCompleteMe/third_party/ycmd/examples/.ycm_extra_conf.py ~/.vim/plugged/YouCompleteMe/third_party/ycmd/cpp/ycm/
从而移动该文件到~/.vim/plugged/YouCompleteMe/third_party/ycmd/cpp/ycm/ 中
然后打开 .vimrc 文件,加入
let g:ycm_global_ycm_extra_conf = ‘~/.vim/plugged/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py’
然后就大工告成了。
最后附上一个小提示:遇到问题可以查找github的issues,里面有很多dalao的解决方案