您的位置:首页 > 运维架构 > Linux

Linux下编译Vim自动补全神器YouCompleteMe(ycm)

2014-12-14 15:15 731 查看
欢迎转载,转载请注明出处,http://blog.csdn.net/up2wing

1、编译vim
ycm需要python支持,而默认的vim是不带python支持的。可以在vim中输入命令

:version


查看是否有“+python”。如果是“-python”,则没有带python支持,需要重新编译。编译步骤比较简单,从vim官网下载src包,进入到src目录。先执行下./configure --help看下有哪些选项:

[root@localhost src]# ./configure --help |grep python
--enable-pythoninterp=OPTS Include Python interpreter. default=no OPTS=no/yes/dynamic
--enable-python3interp=OPTS Include Python3 interpreter. default=no OPTS=no/yes/dynamic
--with-python-config-dir=PATH Python's config directory
--with-python3-config-dir=PATH Python's config directory


因此我们执行

./configure --with-features=huge --enable-pythoninterp=yes --with-python-config-dir=/usr/lib/python2.6/config/ --prefix=/usr
make install -j4


安装后再次检查是否成功,可以检查configure日志:src/auto/config.log,对症解决。如果python configure有问题的话,检查python-dev是否安装。可尝试重新安装python。
编译安装成功后,注意默认安装目录为/usr/local/bin/vim,需要拷贝覆盖/usr/bin/vim。
2、安装YouCompleteMe
ycm需要先在vim插件管理vundle工具中加入,vimrc配置文件可参考https://github.com/up2wing/fox-vim,然后编译才能使用。否则会有错误提示:

[root@localhost ~]# vim
ycm_client_support.[so|pyd|dll] and ycm_core.[so|pyd|dll] not detected; you need to compile YCM before using it. Read the docs!


2.1 自动安装
支持c语言,按照下面,ycm会自动下载并安装:

cd ~/.vim/bundle/YouCompleteMe
./install.sh --clang-completer


2.2 手动安装
首先要下载libclang.so,官网地址:http://llvm.org/releases/。YCM是基于libclang3.5或以上版本设计的,但理论上3.2+也可以。下载后解压。
接下来编译YCM需要的ycm_support_libs。需要cmake产生Makefile,若无需先安装cmake。然后创建编译目录,开始编译ycm_support_libs。

cd ~
mkdir ycm_build
cd ycm_build


如果不需要c语言的语义支持,执行下面就可以:

cmake -G "Unix Makefiles" . ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp




如果需要c语言语义支持,将下面解压的LLVM+Clang目录下面的内容拷贝到~/ycm_temp/llvm_root_dir(with bin, lib,include etc.),然后执行:


cmake -G "Unix Makefiles" -DPATH_TO_LLVM_ROOT=~/ycm_temp/llvm_root_dir . ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp


执行上面的这句可能会失败,需要更新下代码目录,因为ycm需要一些第三方作为子模块:

git submodule update --init --recursive


到此,准备工作终于做好了,make产生ycm_support_libs:

make ycm_support_libs


reference:
1、http://www.bkjia.com/ASPjc/817543.html
2、https://github.com/Valloric/YouCompleteMe
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: