YouCompleteMe
YouCompleteMe is a fast, as-you-type, fuzzy-search code completion engine for Vim
据说YouCompleteMe是一个强大的自动补全插件,就试着安装一下,体验后确实不错,但安装过程也不是一帆风顺的,总结一下过程,希望下次再用时不要再跳坑喽。
环境
首先说下我自己的环境,系统是ubuntu16.04 LTS 64位,VIM版本为7.4.1689 -python +python3,VIM安装插件时使用VIM插件管理工具Vundle安装,假设vim已安装vundle插件管理工具(安装vundle也是很简单的,具体步骤请查看vundle官方说明
安装的前提条件
Ensure that your version of Vim is at least 7.4.143 and that it has support for Python 2 or Python 3 scripting.
Inside Vim, type :version. Look at the first two to three lines of output; it should say Vi IMproved X.Y, where X.Y is the major version of >vim. If your version is greater than 7.4, then you're all set. If your version is 7.4 then look below that where it says, Included patches: >1-Z, where Z will be some number. That number needs to be 143 or higher.
- VIM的版本必须是7.4以上,并且patch大于等于143
VIM的补丁号怎么查看? 使用vim --version
, 然后查看第二行,包含补丁:1-Z,其中的Z即为补丁号 - VIM必须有python2或python3的支持
在终端中使用vim --version grep python
,如果出现的python或python3前面有+号则满足条件,如果都是-号说明不满足条件,需要自己动手编译vim源码或下载7.4以上的版本。
也可以在启动vim后使用:version
,vim命令来查看,还可以使用:echo has('python') || has('python3')
,vim命令查看满足条件不。 - 安装cmake,build-essential,python-dev,python3-dev依赖
如果自己系统中没有这些包,需要先安装这些依赖,这些依赖是编译YCM的必要条件
在ubuntu中可以使用sudo apt-get install cmake build-essential python-dev python3-dev
来安装,其余系统可以参考YouCompleteMe插件官方说明
另外如果在执行YouCompleteMe安装之前没有安装这些依赖,那么会出现错误奥,如fatal error:pyconfig.h No such file or directory
安装
安装的步骤还是很简单的,关键是需要满足前提条件,如果不满足是肯定过不去的。。。
在~/.vimrc的call vundle#end()之前添加Plugin 'Valloric/YouCompleteMe'
,然后保存,然后执行:source ~/.vimrc
vim命令,然后执行:PluginInstall
vim命令,最后就是等待VIM下载YouCompleteMe
下载完成后切换到vundle目录下的YouCompleteMe,如本机的
然后执行./install.py或./install.sh等待安装完成
安装完成后新建一个python文件,然后使用vim编辑一下吧,记得使用C-X C-O体验一下全能补全奥。。。
po一张最后的效果图