一、注意:
1.需将vim版本升级,本人升级到当时最新版本8.1
2.vim8.1 默认只支持python3,不支持python2,而本人需要python2,故用源码安装vim8.1,没有使用apt-get安装方式
3. 网上查询说YouCompleteMe只能支持python2或python3中一个
4.本人使用的vim插件管理器是vim addon manager, 简称VAM
5.在安装完vim8.1后,使用VAM安装YouCompleteMe后,其实并未真正安装完全,需要编译出ycm_core.so,生成后放在如下路径
/root/.vim/vim-addons/YouCompleteMe/third_party/ycmd/ycm_core.so
6.在用VAM安装YouCompleteMe插件后,利用./install.py --clang-completer指令编译时出现如下错误:Could NOT find PythonLibs (missing: PYTHON_INCLUDE_DIRS) (found version "2.7.6"),解决方式是sudo apt-get install build-essential cmake3
7.youcompleteme只支持原生态的python解释器,因此在运行install.py前,应该指定使用原生态的python解释器(lz是将anaconda的bin路径临时性的从PATH中移除),虽然使用anaconda的python解释器也可以编译成功,但是在vim中使用youcompleteme的时候会报错。
二、基本流程
1.升级vim到8.1
2.安装vim addon manger 插件管理器
3.利用VAM安装YouCompleteMe
4.编译YouCompleteMe
5.配置
三、参考文章:
四、安装流程
1、vim8.1安装
sudo apt install libncurses5-dev libgnome2-dev libgnomeui-dev \ libgtk2.0-dev libatk1.0-dev libbonoboui2-dev \ libcairo2-dev libx11-dev libxpm-dev libxt-dev python-dev \ python3-dev ruby-dev lua5.1 liblua5.1-dev libperl-dev git
注:由于Ubuntu已安装python,故python-dev 和python3-dev舍去sudo apt remove vim vim-runtime gvim
随便找个目录进行如下:
- git clone https://github.com/vim/vim.git
- cd vim
- ./configure --with-features=huge --enable-multibyte --enable-rubyinterp=yes --enable-pythoninterp=yes --with-python-config-dir=/usr/lib/python2.7/config-x86_64-linux-gnu --enable-perlinterp=yes --enable-luainterp=yes --enable-gui=gtk2 --enable-cscope --prefix=/usr/local
- make VIMRUNTIMEDIR=/usr/local/share/vim/vim81
- sudo apt install checkinstall
- sudo checkinstall
- sudo make install
- sudo update-alternatives --install /usr/bin/editor editor /usr/local/bin/vim 1
sudo update-alternatives --set editor /usr/local/bin/vim
sudo update-alternatives --install /usr/bin/vi vi /usr/local/bin/vim 1
sudo update-alternatives --set vi /usr/local/bin/vim - vim --version 查看版本
2、VAM安装
- vim ~/.vimrc
- 将如下内用添加
- 1 " put this line first in ~/.vimrc
2 set nocompatible | filetype indent plugin on | syn on
3
4 fun! SetupVAM()
5 let c = get(g:, 'vim_addon_manager', {})
6 let g:vim_addon_manager = c
7 let c.plugin_root_dir = expand('$HOME', 1) . '/.vim/vim-addons'
8
9 " Force your ~/.vim/after directory to be last in &rtp always:
10 " let g:vim_addon_manager.rtp_list_hook = 'vam#ForceUsersAfterDirectoriesToBeLast'
11
12 " most used options you may want to use:
13 " let c.log_to_buf = 1
14 " let c.auto_install = 0
15 let &rtp.=(empty(&rtp)?'':',').c.plugin_root_dir.'/vim-addon-manager'
16 if !isdirectory(c.plugin_root_dir.'/vim-addon-manager/autoload')
17 execute '!git clone --depth=1 git://github.com/MarcWeber/vim-addon-manager '
18 \ shellescape(c.plugin_root_dir.'/vim-addon-manager', 1)
19 endif
20
21 " This provides the VAMActivate command, you could be passing plugin names, too
22 call vam#ActivateAddons([], {})
23 endfun
24 call SetupVAM()
25
26 " ACTIVATING PLUGINS
27
28 " OPTION 1, use VAMActivate
29 "VAMActivate taglist
30
31
32 " OPTION 2: use call vam#ActivateAddons
33 call vam#ActivateAddons(['taglist', 'YouCompleteMe'], {'auto_install' : 0}) - 注:行号33中'taglist', 'YouCompleteMe'是我要添加的插件名,之后运行vim后会自动下载VAM,并询问是否安装此两个插件,安装地址为:~/.vim/vim-addons
3、YouCompleteMe插件安装
- 若按上面步骤则以安装好YouCompleteMe,若没有则添加,VAM就是这么安装插件方便,只需要名字即可,当然VAM还有其他比较正规的安装命令,这个只是激活插件,但没有,所以VAM询问是否安装
4、编译YouCompleteMe
- 进入YouCompleteMe目录,我的是: ~/.vim/vim-addons/YouCompleteMe
- sudo apt-get install build-essential cmake3
- ./install.py --clang-completer (--clang-completer 标志支持c语言家族)
- 完成
5.配置
完成第四步已经成功,配置根据个人喜好,我也菜鸟,本人需要使用anaconda,所以如下:
vim ~/.bashrc
export PATHONPATH=”/path/to/anaconda2/lib/python2.7/site-packages:$PYTHONPATH”
退出
source ~/.bashrc
补充注意:
gcc版本至少4.9,本人升级到5.0以上,很简单指令