ycm是一款vim补全插件,装上插件后利用vim开发时可以自动补全。以下是安装步骤
1.安装vim
sudo apt-get install vim
2.安装vim插件管理工具Vundle
可以去GitHub查看官方文档如何安装。
git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim
下载完成后,可以安装Vundle的官方文档来配置.vimrc文件。
set 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.
" 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
然后使用:PluginInstall命令 就可以开始用Vundle进行管理了。
添加begin/end之间添加PluginInstall ‘Valloric/YouCompleteMe’,保存后,再执行命令:PluginInstall就可以开始安装YouCompleteMe了。
但是我在下载的时候经常就卡住不动了,需要等很长时间。所以建议先把ycm直接下载在~/.vim/bundle/下。
3.下载YouCompleteMe
git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle
git clone https://github.com/Valloric/YouCompleteMe.git ~/.vim/bundle/YouCompleteMe
cd ~/.vim/bundle/YouCompleteMe
git submodule update --init --recursive
下载完成后,安装插件
vim
:PuginInstall
此时安装就会很快
4.添加语言支持(c和c++语言支持)
cd ~/.vim/bundle/YouCompleteMe
./install.py --clang-completer
修改~/.vimrc文件,将以下内容加入
let g:ycm_global_ycm_extra_conf = ‘~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py’ "配置全局路径
let g:ycm_confirm_extra_conf=0 "每次直接加载该文件,不提示是否要加载
同时要补全语言,要对~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py进行修改:
在flags下添加(如果有相关内容只需把相应版本改为Ubuntu内装的版本)
'-isystem',
'/usr/include',
'-isystem',
'usr/include/c++/5.4.0'
'-isystem',
'usr/include/x86_64-linux-gnu/c++',
5.缺少~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py文件的办法
安装完后发现~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py文件不存在,直接自己创建将如下内容写入即可
import os
import ycm_core
flags = [
'-Wall',
'-Wextra',
'-Werror',
'-Wno-long-long',
'-Wno-variadic-macros',
'-fexceptions',
'-DNDEBUG',
'-std=c++11',
'-x',
'c++',
'-I',
'/usr/include',
'-isystem',
'/usr/lib/gcc/x86_64-linux-gnu/5/include',
'-isystem',
'/usr/include/x86_64-linux-gnu',
'-isystem'
'/usr/include/c++/5',
'-isystem',
'/usr/include/c++/5/bits'
]
SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', ]
def FlagsForFile( filename, **kwargs ):
return {
'flags': flags,
'do_cache': True
}