1.安装YouCompleteMe
在.vimrc中插入
Plugin 'Valloric/YouCompleteMe'
利用git下载安装包
git clone https://github.com/Valloric/YouCompleteMe.git ~/.vim/bundle/YouCompleteMe
然后进入YouCompeteMe所在的文件夹:~/.vim/bundle/YouCompleteMe,运行:
python3 install.py --clang-completer --system-libclang
其中编译安装的过程中,不断提示编译所缺少的依赖,会有错误提示,按照提示安装缺少的依赖就好,其中比较重要的是clang,所以先需要运行
sudo apt-get install clang
运行install.py时会显示
最后在.vimrc文件中,添加配置信息:
set ts=4set expandtabset shiftwidth=4set softtabstop=4set number"vundle"filetype offset rtp+=~/.vim/bundle/Vundle.vimcall vundle#begin()Plugin 'VundleVim/Vundle.vim'Plugin 'Valloric/YouCompleteMe'Plugin 'davidhalter/jedi-vim'call vundle#end()filetype plugin indent on"youcompleteme""默认配置文件路径"let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/.ycm_extra_conf.py' "配置全局路径"log""let g:ycm_server_keep_logfiles=1"let g:ycm_sever_log_level='debug'"打开vim时不再询问是否加载ycm_extra_conf.py配置""let g:ycm_confirm_extra_conf=0"set completeopt=longest,menu"python解释器路径"let g:ycm_path_to_python_interpreter='/home/wdh/anaconda3/bin/python3'"let g:ycm_python_binary_path = '/home/wdh/anaconda3/bin/python3' "python 环境"是否开启语义补全"let g:ycm_seed_identifiers_with_syntax=1"是否在注释中也开启补全"let g:ycm_complete_in_comments=1let g:ycm_collect_identifiers_from_comments_and_strings = 0"开始补全的字符数"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"字符串中也开启补全"let g:ycm_complete_in_strings = 1let g:ycm_seed_identifiers_with_syntax=1 "补全关键字 "离开插入模式后自动关闭预览窗口"autocmd InsertLeave * if pumvisible() == 0|pclose|endif"回车即选中当前项""inoremappumvisible() ? ' ' : '\ ' "上下左右键行为""inoremap pumvisible() ? '\ ' : '\ '"inoremap pumvisible() ? '\ ' : '\ '"inoremap pumvisible() ? '\ \ \ ' : '\ '"inoremap pumvisible() ? '\ \ \ ' : '\ '\