Ubuntu12.04安装YouCompleteMe插件

以前用的都是ctags+omnicomplete+acp的方式,这次换成clang自解析的方式尝试一把。

 

自从知道了Vundle,妈妈再也不用担心我麻烦地下插件了

0. 安装必要组件

sudo apt-get 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 ruby-dev mercurial checkinstall

1. 升级Vim 到7.4

1) 自己编译

I) 卸载原有的Vim

sudo apt-get remove vim vim-tiny vim-common vim-runtime gvim vim-gui-common

下载最新的Vim源码

hg clone https://vim.googlecode.com/hg/ vim

cd vim
./configure --with-features=huge \
            --enable-rubyinterp=yes \
            --enable-pythoninterp=yes \
            --enable-python3interp=yes \
            --enable-perlinterp=yes \
            --enable-luainterp=yes \
            --enable-gui=gtk2 --enable-cscope --prefix=/usr
make VIMRUNTIMEDIR=/usr/share/vim/vim74
make install

2) 手动添加PPA(Personal Package Archives)

sudo add-apt-repository ppa:nmi/vim-snapshots
sudo apt-get update
sudo apt-get install vim

2. 安装llvm & clang

到 http://llvm.org/releases/download.html#3.3 下载编译后的二进制文件

wget http://llvm.org/releases/3.3/clang+llvm-3.3-amd64-Ubuntu-12.04.2.tar.gz

解压到/

tar -zxf clang+llvm-3.3-amd64-Ubuntu-12.04.2.tar.gz
cd clang+llvm-3.3-amd64-Ubuntu-12.04.2/
cp -r * /

 

如果在命令行输入clang,输出clang: error: no input files,说明安装成功

3. 下载 Vundle

git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle

Vundle可以让Vim自动从github等地方下载插件,而不用每次去vim.org上手动下载

修改.vimrc

set nocompatible              " be iMproved
set nu
set noswapfile
syntax on
set backspace=2
set tabstop=2
set shiftwidth=2
set completeopt=menu
:colorscheme ron
set cindent
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
Bundle 'gmarik/vundle'
Bundle 'Valloric/YouCompleteMe'
Bundle 'scrooloose/syntastic'
""""""""""syntastic""""""""""""
let g:syntastic_check_on_open = 1
let g:syntastic_cpp_include_dirs = ['/usr/include/']
let g:syntastic_cpp_remove_include_errors = 1
let g:syntastic_cpp_check_header = 1
let g:syntastic_cpp_compiler = 'clang++'
"set error or warning signs
let g:syntastic_error_symbol = 'x'
let g:syntastic_warning_symbol = '!'
"whether to show balloons
let g:syntastic_enable_balloons = 1

""""""""""""YCM""""""""""""""""""""
let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'
let g:ycm_collect_identifiers_from_tags_files = 1
let g:ycm_seed_identifiers_with_syntax = 1
let g:ycm_confirm_extra_conf = 0

 

然后打开vim
在命令模式下输入
:BundleInstall,就会发现vim自动开始下载插件了
NOTE:
YouCompleteMe插件要下载很久,请稍安勿躁:-)

4. 编译ycm_core & ycm_support_libs

cd ~
mkdir ~/ycm_build
cd ~/ycm_build
cmake -G "Unix Makefiles"  ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ -DEXTERNAL_LIBCLANG_PATH=/lib/libclang.so
make ycm_core
make ycm_support_libs

这里要注意的是-DEXTERNAL_LIBCLANG_PATH这个参数,用于指定libclang.so的位置

5. 配置.ycm_extra_conf.py

~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py

在这个文件的flags尾部添加:
'-isystem',
'/usr/include',
'-isystem',
'/usr/include/c++/'

最后

该文章转自http://blog.csdn.net/unhappypeople/article/details/19160243,同时改正其中的有些细小错误。

你可能感兴趣的:(Ubuntu12.04安装YouCompleteMe插件)