vim 智能提示插件 YouCompleteMe安装

Posted 雪域蓝心

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vim 智能提示插件 YouCompleteMe安装相关的知识,希望对你有一定的参考价值。

按照网上的教程安装该软件,没有一篇是成功的(也有可能是没找对)。自己从网上东拼西凑的,终于让自己的vim智能识别了。

1. 升级 vim: (ubuntu)

sudo add-apt-repository ppa:jonathonf/vim
sudo apt update
sudo apt install vim

2. 安装vundle
git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle

3.下载ycm
cd ~/.vim/
git clone --recursive https://github.com/Valloric/YouCompleteMe.git
cd ~/.vim/bundle/YouCompleteMe
git submodule update --init --recursive


4. 安装libclang
apt-get install llvm-3.9 clang-3.9 libclang-3.9-dev libboost-all-dev

5. 编译ycm_core库
mkdir 123 && cd 123

cmake -G
"Unix Makefiles" -DUSE_SYSTEM_BOOST=ON -DUSE_SYSTEM_LIBCLANG=ON . ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp
或者
cmake -G "Unix Makefiles" -DUSE_SYSTEM_BOOST=ON -DEXTERNAL_LIBCLANG_PATH=/usr/lib/x86_64-linux-gnu/libclang-3.9.so . ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp #未验证

cmake --build . --target ycm_core --config Release

6. 配置
#perl警告处理
echo "export LC_ALL=C" >> /root/.bashrc
source /root/.bashrc

cp ~/.vim/bundle/YouCompleteMe/third_party/ycmd/examples/.ycm_extra_conf.py ~/.vim/

配置vimrc
"~/.vimrc
let g:ycm_server_python_interpreter=\'/usr/bin/python2.7\'      " 当时编译python的版本
let g:ycm_global_ycm_extra_conf=\'~/.vim/.ycm_extra_conf.py\'

set nocompatible " be iMproved
set rtp+=~/.vim/bundle/vundle/

call vundle#rc()

"let Vundle manage Vundle
" required!
Bundle \'scrooloose/syntastic\'
Bundle \'gmarik/vundle\'

" My bundles here:
"
" original repos on GitHub
Bundle \'tpope/vim-fugitive\'
Bundle \'Lokaltog/vim-easymotion\'
Bundle \'rstacruz/sparkup\', {\'rtp\': \'vim/\'}
Bundle \'tpope/vim-rails.git\'
" vim-scripts repos
Bundle \'L9\'
Bundle \'FuzzyFinder\'
" non-GitHub repos
Bundle \'git://git.wincent.com/command-t.git\'
" Git repos on your local machine (i.e. when working on your own plugin)
Bundle \'file:///Users/gmarik/path/to/plugin\'
" ...
Bundle \'Valloric/YouCompleteMe\'
filetype plugin indent on " required!
" 编码为utf-8
set fileencodings=utf-8,gb2312,gbk,gb18030
set termencoding=utf-8
set encoding=utf-8


" YouCompleteMe
set runtimepath+=~/.vim/bundle/YouCompleteMe
let g:ycm_collect_identifiers_from_tags_files = 1           " 开启 YCM 基于标签引擎
let g:ycm_collect_identifiers_from_comments_and_strings = 1 " 注释与字符串中的内容也用于补全
let g:syntastic_ignore_files=[".*\\.py$"]
let g:ycm_seed_identifiers_with_syntax = 1                  " 语法关键字补全
let g:ycm_complete_in_comments = 1
let g:ycm_confirm_extra_conf = 0
let g:ycm_key_list_select_completion = [\'<c-n>\', \'<Down>\']  " 映射按键, 没有这个会拦截掉tab, 导致其他插件的tab不能用.
let g:ycm_key_list_previous_completion = [\'<c-p>\', \'<Up>\']
let g:ycm_complete_in_comments = 1                          " 在注释输入中也能补全
let g:ycm_complete_in_strings = 1                           " 在字符串输入中也能补全
let g:ycm_collect_identifiers_from_comments_and_strings = 1 " 注释和字符串中的文字也会被收入补全
let g:ycm_global_ycm_extra_conf=\'~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py\'
let g:ycm_show_diagnostics_ui = 0                           " 禁用语法检查
inoremap <expr> <CR> pumvisible() ? "\\<C-y>" : "\\<CR>" |            " 回车即选中当前项
nnoremap <c-j> :YcmCompleter GoToDefinitionElseDeclaration<CR>|     " 跳转到定义处
"let g:ycm_min_num_of_chars_for_completion=2                 " 从第2个键入字符就开始罗列匹配项


显示结果:

 

 

以上是关于vim 智能提示插件 YouCompleteMe安装的主要内容,如果未能解决你的问题,请参考以下文章

Fedora 27安装vim插件YouCompleteMe

mac vim升级支持插件YouCompleteMe

Fedora 29安装vim插件YouCompleteMe

Fedora 29安装vim插件YouCompleteMe

CentOS7.2安装Vim8和YouCompleteMe

Windows 10环境安装VIM代码补全插件YouCompleteMe