Vim插件之YouCompleteMe

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Demorngel/article/details/69054982

纯粹个人记录备份而已,如有错误,欢迎指正,更新于2018/5/13

YouCompleteMe,Vim的智能补全插件,能提供不逊于大型IDE的补全体验,安装这个插件需要先安装python-pil的包(有的发行版上可能没有这个包,可以试试搜索python-pillow),如果不事先解决这个问题的话,安装的时候就会提示No module names future,解决方法如下

$ sudo aptitude install python-pil python3-pil

如果仍然不能解决的话,就在终端使用pip解决

$ sudo pip install future

此外有时也会提示No module names frozendict这时用上面的方法继续用pip安装上frozendict模块即可。
安装完成ycm以后需要编译出库才能正常使用,而要编译出库则需要python开发库的支持,在终端执行

$ sudo aptitude install python-dev python3-dev

做完这些准备工作以后就可以开始编译了,ycm还额外支持C、C++、C#、go、typescript、javascript、rust等语言的补全,这里以添加C家族、Java和golang的支持为例,编译方法如下,其他语言的请参考官网的说明

$ cd ~/.vim/plugged/YouCompleteMe
$ ./install.py --clang-completer --java-completer --go-completer

编译完成以后再把.ycm_extra_conf.py复制到~目录

$ cp third_party/ycmd/examples/.ycm_extra_conf.py ~/

最后,ycm的配置如下

"YouCompleteMe
"配置默认文件路径
let g:ycm_global_ycm_extra_conf = '~/.ycm_extra_conf.py'
"打开vim时不再询问是否加载ycm_extra_conf.py配置
let g:ycm_confirm_extra_conf = 0
set completeopt=longest,menu
"自动开启语义补全
let g:ycm_seed_identifiers_with_syntax = 1
"在注释中也开启补全
let g:ycm_complete_in_comments = 1
let g:ycm_collect_identifiers_from_comments_and_strings = 0
"字符串中也开启补全
let g:ycm_complete_in_strings = 1
let g:ycm_collect_identifiers_from_tags_files = 1
"开启基于tag的补全,可以在这之后添加需要的标签路径  
let g:ycm_collect_identifiers_from_tags_files = 1
"开始补全的字符数
let g:ycm_min_num_of_chars_for_completion = 2
"补全后自动关闭预览窗口
let g:ycm_autoclose_preview_window_after_completion = 1
"禁止缓存匹配项,每次都重新生成匹配项
let g:ycm_cache_omnifunc=0
"离开插入模式后自动关闭预览窗口
autocmd InsertLeave * if pumvisible() == 0|pclose|endif
"语法关键字补全
let g:ycm_seed_identifiers_with_syntax = 1  
"整合UltiSnips的提示
let g:ycm_use_ultisnips_completer = 1 
"在实现和声明之间跳转,并分屏打开
let g:ycm_goto_buffer_command = 'horizontal-split'
nnoremap <Leader>g :YcmCompleter GoTo<CR>
"与syntastic有冲突,建议关闭
let g:ycm_show_diagnostics_ui = 0
"let g:ycm_error_symbol = '>>'
"let g:ycm_warning_symbol = '>>'
let g:ycm_enable_diagnostic_signs = 0
let g:ycm_enable_diagnostic_highlighting = 0
let g:ycm_echo_current_diagnostic = 0

另外,ycm还能定义黑白名单,做到按需加载,下面是官方文档的两个例子,仅作参考

let g:ycm_filetype_blacklist = {
        \ 'tagbar' : 1,
        \ 'qf' : 1,
        \ 'notes' : 1,
        \ 'markdown' : 1,
        \ 'unite' : 1,
        \ 'text' : 1,
        \ 'vimwiki' : 1,
        \ 'pandoc' : 1,
        \ 'infolog' : 1,
        \ 'mail' : 1
        \}
let g:ycm_filetype_specific_completion_to_disable = {
        \ 'gitcommit': 1
        \}

猜你喜欢

转载自blog.csdn.net/Demorngel/article/details/69054982
今日推荐