0x00. 簡介
YouCompleteMe號稱Vim的自動補全神器,YouCompleteMe: a code-completion engine for Vim,該項目在github的地址:YouCompleteMe。
0x01. Requirements
Vim is at least 7.3.584 andit has support for python2 scripting.
0x02. 用Vundle來安裝YCM(YouCompleteMe)
安裝其實非常簡單,在.vimrc文件中加入語句Bundle 'Valloric/YouCompleteMe'即可,保存,退出,然后再次打開Vim,normal模式下輸入 :BundleInstall 即開始下載。如下圖:
也可以切換至.vim/bundle下手動下載,輸入如下命令:
git clone https://github.com/Valloric/YouCompleteMe.git
手動下載完后檢查倉庫的完整性,切換到 YouCompleteMe目錄下,輸入如下命令:
git submodule update --init --recursive
0x03. 下載最新的libclang
Clang是一個開源的編譯器,它可以編譯C/C++/Objective-C/Objective-C++.Clang提供的libclang庫是用來給YCM為這些語言提供語義補全的引擎。和YCM配合的libclang版本必須 >=3.6,但理論上也是可以和 3.2+ 版本的libclang配合使用的。下載最新的libclang如下:
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_build3 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,如下:
"YouCompleteMelet 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
城里人真會玩:)
自己再配置配置可以起飛了~
新聞熱點
疑難解答
圖片精選