要安裝YouCompleteMe ,vim須支持python。看是否支持,能夠在vim中:version 查看, 若是python前有+號,就是支持,減號就是不支持。html
若是不支持,須要以編譯安裝方式從新安裝vim。python
編譯配置選項:c++
./configure --with-features=huge --enable-pythoninterp --enable-python3interp --enable-luainterp --enable-multibyte --enable-sniff --enable-fontsetgit
在個人機器上裝有python2.7.5 和 python3.3, 但加了enable-python3interp參數依然沒有支持py3,不知何故,先無論,YouCompleteMe 只要求有py2.6以上。github
安裝vundle插件vim
git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundlepython2.7
在.vimrc中配置ide
set nocompatible " be iMproved, required filetype off " required " set the runtime path to include Vundle and initialize set rtp+=~/.vim/bundle/vundle/ call vundle#rc() " alternatively, pass a path where Vundle should install plugins "let path = '~/some/path/here' "call vundle#rc(path) " let Vundle manage Vundle, required Plugin 'gmarik/vundle' " The following are examples of different formats supported. " Keep Plugin commands between here and filetype plugin indent on. " scripts on GitHub repos Plugin 'tpope/vim-fugitive' Plugin 'Lokaltog/vim-easymotion' Plugin 'tpope/vim-rails.git' " 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/'} " scripts from http://vim-scripts.org/vim/scripts.html Plugin 'L9' Plugin 'FuzzyFinder' " scripts not 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' " ... filetype plugin indent on " required Bundle 'Valloric/YouCompleteMe'
保存退出,打開vim,輸入 :BundleInstall 進行自動安裝ui
進程以下,+號表示已經安裝,>表示正在安裝。this
. Plugin 'gmarik/vundle' |~ + Plugin 'tpope/vim-fugitive' |~ + Plugin 'Lokaltog/vim-easymotion' |~ + Plugin 'tpope/vim-rails.git' |~ + Plugin 'rstacruz/sparkup' |~ + Plugin 'L9' |~ + Plugin 'FuzzyFinder' |~ > Plugin 'git://git.wincent.com/command-|~ t.git' |~ Plugin 'file:///home/gmarik/path/to/pl|~ ugin' |~ Plugin 'Valloric/YouCompleteMe' |~ Helptags
結束時有個錯誤,這是正常的,由於ycm須要手工編譯出庫文件
Done! With errors; press l to view log
ycm_client_support.[so|pyd|dll] and ycm_core.[so|pyd|dll] not detected; you need
to compile YCM before using it. Read the docs!
到 .vim/bundle/YouCompleteMe 下跑
./install.sh --clang-completer
參數是爲了支持c/c++ 的補全。
安裝完成後進行一些簡單的配置就能夠使用。
YouCompleteMe 的補全配置文件在/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py,這是個隱藏文件。
默認會使用這個文件,也能夠把這個文件copy到工程的根目錄中做修改,打開工程文件時會優先使用當前目錄下的配置文件。
若是找不到,會根據配置中的ycm_global_ycm_extra_conf 進行查找。
在.vimrc 中添加
let mapleader = "," " 這個leader就映射爲逗號「,」
let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py' 「配置默認的ycm_extra_conf.pynnoremap <leader>jd :YcmCompleter GoToDefinitionElseDeclaration<CR> 「按,jd 會跳轉到定義let g:ycm_confirm_extra_conf=0 「打開vim時再也不詢問是否加載ycm_extra_conf.py配置let g:ycm_collect_identifiers_from_tag_files = 1 "使用ctags生成的tags文件