centos8 安装 YouCompleteMe

centos 8.1 上自带的 vim 版本为 8.0 版本,已经可以支持 YouCompleteMe.

安装涉及到大量的从 github 拉取源码,所以首先配置 git 的代理,相比直接从国内的网络过去要节省很多时间。

git config --global http.proxy socks5://192.168.0.103:5555
git config --global https.proxy socks5://192.168.0.103:5555

1、下载安装 vim 插件管理器 vbundle。

git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

2、修改 .vimrc 配置文件。

set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

" Plugins
Plugin 'Valloric/YouCompleteMe'

call vundle#end()
filetype plugin indent on

Plugin 后边的参数表示插件在 github 上的地址,修改完,重启 vim,在底行模式输入 :PluginList (区分大小写)可以看到。

3、下载安装 YouCompleteMe。

下载 .YouCompleteMe 的源码。

git clone https://github.com/Valloric/YouCompleteMe.git ~/.vim/bundle/YouCompleteMe

当前工作路径切到 ~/.vim/bundle/YouCompleteMe 下。

python ./install.py --clang-completer

直接编译构建,会提示

File /root/.vim/bundle/YouCompleteMe/third_party/ycmd/build.py does not exist; you probably forgot to run:
    git submodule update --init --recursive

按提示,执行

git submodule update --init --recursive

然后再 python ./install.py --clang-completer,完成。

--clang-completer 选项表示补全 C/C++ 还有 python,当然还支持一些其他语言:--go-completer --js-completer 等。

4、修改 YouCompleteMe 的配置,即使用 example 路径下的配置作为默认配置。

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

最终的 ~/.vimrc 配置:

" 设置 tab 键为 4 个空格宽度
filetype plugin indent on
" show existing tab with 4 spaces width
set tabstop=4
" when indenting with '>', use 4 spaces width
set shiftwidth=4
" On pressing tab, insert 4 spaces
set noexpandtab


" 插件管理
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

" Plugins
Plugin 'Valloric/YouCompleteMe'

call vundle#end()
filetype plugin indent on



" ctrl + j 强制触发一次补全
let g:ycm_key_invoke_completion = '<c-j>'
" 自动加载配置文件,不用每次 vim 打开都提示
let g:ycm_global_ycm_extra_conf='~/.vim/bundle/YouCompleteMe/.ycm_extra_conf.py'

" 标记设置当前行列
set cursorcolumn
set cursorline

" 显示行号
set number

noexpandtab / expandtab 表示使用制表符还是空格来表示 tab 键,个人习惯使用制表符键。

比较有用的是设置手动强制触发一次补全提示(在 vim 的插入模式下才有用),在光标移动到其他地方再回来非常好用,效果同 VS 的 ctrl + j 一样。

看看效果。

C++ 版本:

 

golang 版本:

 golang 因为涉及到 go get 下载依赖的包,所以需要设置代理,否则会因为依赖的包无法下载导致最终功能不正常。

#为 go get 设置代理:

export http_proxy=http://192.168.0.102:5556
export https_proxy=http://192.168.0.102:5556

 

另外,这个网站 https://vimawesome.com/ 可以看到各种有趣的 vim 插件。

 

 

Guess you like

Origin blog.csdn.net/zhouguoqionghai/article/details/106160195