YouCompleteMe 是很强大的vim插件,可以提供强大的补齐功能,曾经多次尝试安装,都没有配置成功,最近在一个契机下,看到有同事的配置,自己在边尝试和边咨询后,终于也搞定了,遂记录下。
官网有最好的文档:https://github.com/Valloric/YouCompleteMe#installation
这边记录一些步骤和推荐配置:
1.安装
1.安装vim,需要大于 7.4.1578,可以通过源码安装,还是比较方便的:https://github.com/Valloric/YouCompleteMe/wiki/Building-Vim-from-source
需要支持python2或者python3(二选一),编译方式如(python2):
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:
~/.vimrc加入:
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> "}
安装新配置的插件:
vim -c PluginInstall
3.拷贝默认.ycm_extra_conf.py
cp .vim/bundle/YouCompleteMe/third_party/ycmd/examples/.ycm_extra_conf.py ~
4.编译安装YouCompleteMe
cd ~/.vim/bundle/YouCompleteMe ./install.py -h # 通过-h看需要的语言支持,通过提示看
#如 golang支持:
./install.py --go-completer
#全量支持:
./install.py --all
2.效果:
3.功能:
1.输入时有自动提示,通过tab来选择
2.标识符可以通过ctrl+g来跳转,ctrl+o返回,ctrl+i再进入(方便阅读代码)