YouCompleteMe 安装教程
YouCompleteMe作为Vim中最好用(没有之一)的代码自动补全插件,却同时又是最不容易安装的插件之一。其实在YCM的Github官网,有非常详细完整的安装说明。如果在Mac OS X, Windows, Ubuntu, FreeBSD/OpenBSD或Fedora上安装YCM,且英语还Okay的话,建议直接移步官方安装说明文档。但官方说明文档却没有对在CentOS与Debian中安装YCM的详细说明。所以在这里总结一下具体的步骤给大家作一个参考。
在CentOS中安装YCM
使用 Vundle 安装YCM
Vundle(Vim Bundle的缩写)是一个针对Vim的插件管理器。相较于Vim本身混乱的插件结构,使用Vundle来管理插件就显得非常得方便、简洁。用户只需要在Github上找到自己想要的插件的名字,并将其添加到.vimrc文件中,之后的安装,更新和卸载等操作都可以由vundle来完成了。
- 下载Vundle
1
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
- 编辑 .vimrc 文件
将以下代码添加至你的.vimrc文件中。同时,你也可以根据需求来添加其他你想要安装的vim插件。1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.
" plugin on GitHub repo
Plugin 'Valloric/YouCompleteMe'
" plugin from http://vim-scripts.org/vim/scripts.html
" Plugin 'L9'
" Git plugin not hosted on GitHub
"Plugin 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own plugin)
"Plugin 'file:///home/gmarik/path/to/plugin'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
"Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" Install L9 and avoid a Naming conflict if you've already installed a
" different version somewhere else.
" Plugin 'ascenator/L9', {'name': 'newL9'}
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList - lists configured plugins
" :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line - 安装插件
打开Vim并运行:PluginInstall
指令。
这一步骤可能所需要的时间较长,需要耐心地等待它安装完成。
安装编译YCM所需要的软件
- 安装开发工具与CMake:
1
yum install build-essential cmake
- 并确保python头文件包已经正确安装:
1
yum install python-devel rh-python36-python-devel.x86_64
如果你的CentOS上还未安装Python3,那么运行以下命令完成Python3.6的安装:
1
2sudo yum install centos-release-scl
sudo yum install rh-python36
需要的话,可以将Python3.6作为默认的Python来运行:
1
scl enable rh-python36 bash
编译YCM
完成包含对C语言家族语义支持的YCM编译
1
2cd ~/.vim/bundle/YouCompleteMe
./install.py --clang-completer不包含语义支持则直接运行install.py
1
2cd ~/.vim/bundle/YouCompleteMe
./install.py如果需要简单的开启对所有语言的支持,则可以用–all标识。
1
2cd ~/.vim/bundle/YouCompleteMe
./install.py --all