YouCompleteMe 是很強大的vim插件,能夠提供強大的補齊功能,曾經屢次嘗試安裝,都沒有配置成功,最近在一個契機下,看到有同事的配置,本身在邊嘗試和邊諮詢後,終於也搞定了,遂記錄下。python
官網有最好的文檔:https://github.com/Valloric/YouCompleteMe#installation git
這邊記錄一些步驟和推薦配置:github
1.安裝vim,須要大於 7.4.1578,能夠經過源碼安裝,仍是比較方便的:https://github.com/Valloric/YouCompleteMe/wiki/Building-Vim-from-sourcegolang
須要支持python2或者python3(二選一),編譯方式如(python2):vim
cd ~ git clone https://github.com/vim/vim.git cd vim ./configure --with-features=huge \ --enable-multibyte \ --enable-rubyinterp=yes \ --enable-pythoninterp=yes \ --with-python-config-dir=/usr/lib/python2.7/config \ --enable-python3interp=yes \ --enable-perlinterp=yes \ --enable-luainterp=yes \ --enable-gui=gtk2 \ --enable-cscope \ --prefix=/usr/local make VIMRUNTIMEDIR=/usr/local/share/vim/vim81 sudo make install
2.經過Vundle,安裝YouCompleteMe:ruby
~/.vimrc加入:bash
Plugin 'Valloric/YouCompleteMe' "{ set completeopt-=preview let g:ycm_autoclose_preview_window_after_insertion = 1 let g:ycm_autoclose_preview_window_after_completion = 1 let g:ycm_add_preview_to_completeopt = 0 let g:ycm_complete_in_comments = 1 let g:ycm_confirm_extra_conf = 0 let g:ycm_global_ycm_extra_conf = '~/.ycm_extra_conf.py' let g:ycm_min_num_of_chars_for_completion=1 nnoremap <F4> :YcmDiags<CR> nnoremap <F5> :YcmForceCompileAndDiagnostics<CR> nnoremap <C-g> :YcmCompleter GoTo<CR> nnoremap <C-t> :YcmCompleter GetType<CR> nnoremap <leader>ycmd :YcmCompleter GetDoc<CR> "}
安裝新配置的插件:python2.7
vim -c PluginInstall
3.拷貝默認.ycm_extra_conf.pyui
cp .vim/bundle/YouCompleteMe/third_party/ycmd/examples/.ycm_extra_conf.py ~lua
4.編譯安裝YouCompleteMe
cd ~/.vim/bundle/YouCompleteMe ./install.py -h # 經過-h看須要的語言支持,經過提示看
#如 golang支持:
./install.py --go-completer
#全量支持:
./install.py --all
1.輸入時有自動提示,經過tab來選擇
2.標識符能夠經過ctrl+g來跳轉,ctrl+o返回,ctrl+i再進入(方便閱讀代碼)