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再进入(方便阅读代码)