9. VIM 系列 - YouCompleteMe 实现代码补全

环境准备

$ sudo apt install build-essential cmake python3-dev  python-dev
$ sudo apt install clang libclang-dev

插件安装

插件安装

Plug 'Valloric/YouCompleteMe'

编译插件

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

配置插件

let g:ycm_add_preview_to_completeopt = 0
let g:ycm_show_diagnostics_ui = 0
let g:ycm_server_log_level = 'info'
let g:ycm_min_num_identifier_candidate_chars = 2
let g:ycm_collect_identifiers_from_comments_and_strings = 1
let g:ycm_complete_in_strings=1
let g:ycm_key_invoke_completion = '<c-z>'
highlight PMenu ctermfg=0 ctermbg=242 guifg=black guibg=darkgrey
highlight PMenuSel ctermfg=242 ctermbg=8 guifg=darkgrey guibg=black
set completeopt=menu,menuone

noremap <c-z> <NOP>

let g:ycm_semantic_triggers =  {
            \ 'c,cpp,python,java,go,erlang,perl': ['re!\w{2}'],
            \ 'cs,lua,javascript': ['re!\w{2}'],
            \ }

let g:ycm_filetype_whitelist = { 
            \ "c":1,
            \ "cpp":1, 
            \ "objc":1,
            \ "sh":1,
            \ "zsh":1,
            \ "zimbu":1,
            \ }
            
let g:ycm_global_ycm_extra_conf='~/.ycm_extra_conf.py'

let g:ycm_confirm_extra_conf = 0

指定.ycm_extra_conf.py路径:

.ycm_extra_conf.py 拷贝到home 目录

$ cp ~/.vim/plugged/YouCompleteMe/third_party/ycmd/.ycm_extra_conf.py ~/

自定义.ycm_extra_conf.py: 一个项目应该有一个自定义的配置,这样才能语义补全,将自定义好的配置放到项目的根目录即可。

效果图

posted @ 2019-04-21 13:30  standardzero  阅读(1518)  评论(0编辑  收藏  举报