Ubuntu15.04YouCompleteMe插件安裝

0x00. 簡介html

YouCompleteMe號稱Vim的自動補全神器,YouCompleteMe: a code-completion engine for Vim,該項目在github的地址:YouCompleteMepython

0x01. Requirementslinux

Vim is at least 7.3.584 and it has support for python2 scripting.c++

0x02. 用Vundle來安裝YCM(YouCompleteMe)git

安裝其實很是簡單,在.vimrc文件中加入語句 Bundle 'Valloric/YouCompleteMe' 便可,保存,退出,而後再次打開Vim,normal模式下輸入 :BundleInstall 即開始下載。以下圖:github

也能夠切換至 .vim/bundle 下手動下載,輸入以下命令:vim

git clone https://github.com/Valloric/YouCompleteMe.git

手動下載完後檢查倉庫的完整性,切換到 YouCompleteMe 目錄下,輸入以下命令:ui

git submodule update --init --recursive

0x03.  下載最新的libclangspa

Clang是一個開源的編譯器,它能夠編譯C/C++/Objective-C/Objective-C++. Clang提供的libclang庫是用來給YCM爲這些語言提供語義補全的引擎。和YCM配合的libclang版本必須 >=3.6 ,但理論上也是能夠和 3.2+ 版本的libclang配合使用的。下載最新的libclang以下:3d

sudo apt-get install libclang-dev

0x04. 編譯YCM須要的ycm_support_libs庫

首先要確保你已經安裝類cmake。若是沒有,請按以下安裝:

sudo apt-get install cmake

其次須要確保你有一些 Python 頭文件。若是沒有,請按以下安裝:

sudo apt-get install python-dev

接下來,建立新的文件夾 ycm_build 進行編譯,以下:

1 cd ~
2 mkdir ycm_build
3 cd ycm_build

不須要語義補全的童鞋們,直接執行下面的語句:

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

然並卵啊,俺們是須要語義補全的呀~,那麼請先去 llvm.org 下載最新的 clang+llvm 包,而後把它們解壓到 ~/ycm_temp/llvm_root_dir 文件夾下。接着,執行以下語句:

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

再接着要開始編譯 ycm_support_libs 庫,執行以下語句:

make ycm_support_libs

這樣就編譯完了。

0x05. 配置YCM

本渣開始覺得編譯完了就完事了,誰知道再次打開Vim,它來了這麼一句:No .ycm_extra_conf.py file detected, so no compile flags are available. Thus no semantic support for C/C++/ObjC/ObjC++. 哦呵呵呵~

~/.vim/bundle/YouCompleteMe 文件夾下一看。。。沒有 cpp !沒有 cpp !沒有 cpp !

咋辦?新建唄。。。而後把 YCM‘S own .ycm_extra_conf.py 文件拷貝到相應的文件夾下。

接着再次打開 .vimrc 配置YCM,以下:

"YouCompleteMe
let g:ycm_global_ycm_extra_conf='~/.vim/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py'

以後再次打開Vim便可。

爲了補全,咱們還須要在 .ycm_extra_conf.py 文件中進行配置,以下:

1 '-isystem',
2 '/usr/include',
3 '-isystem',
4 '/usr/include/c++/4.9.2',
5 '-isystem',
6 '/usr/include',
7 '/usr/include/x86_64-linux-gnu/c++',

0x06. Summary

城裏人真會玩:)

本身再配置配置能夠起飛了~

相關文章
相關標籤/搜索