YouCompleteMe 安装配置方法

通过这篇文章,你可以了解到:
- 如何为 Ubuntu 远程服务器 Vim 安装 YouCompleteMe 插件

问题描述

YouCompleteMe 是一款用于代码自动提示的 Vim 插件,可以在 Vim 中实现类似于 IDE 代码提示类似的功能。我大概在很久之前就听说过这个插件的强大,但由于我们网络的原因,导致安装总不是那么顺利,因此就搁置了。最近经常做一些修改远程服务器上的程序代码并且进行相关调试,因此再次仔细研究了一下这个插件的安装配置方法,并且成功安装。

关于代码提示,曾经在学习编程的时候,听到很多前辈都说只有新手才需要靠代码提示来写代码。但经过了自己的实践,我个人认为,在实际工作中,编写代码的过程中,尽可能的使用代码提示自动补全的代码,不仅能加快工作效率,更能够减少处理 Bug 的时间,因为人手输入,总可能会出现手误输入多或者少一个字母的情况,这些情况往往在编码过程中不容易察觉,从而导致在运行 DeBug 时会出现程序 Crash 或者跑不通的情况,既增加了挫败感又延长了工作时间,因此利用代码提示工具的辅助,把宝贵的注意力放在真正重要的工作上,会让工作更高效以及显得更有意义。



YouCompleteMe 安装配置步骤

安装 YouCompleteMe 的主要步骤如下:

- 安装 Vundle
- 配置好系统的 Python 环境以及 CMake
- 通过 Git Clone 下载 YouCompleteMe
- 安装 YouCompleteMe

Vundle 安装

Vundle 是一个 Vim 的插件管理器,安装方法如下:
- 利用 git clone 下载 Vundle

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


  • 将 Vundle 配置添加到 .vimrc 的头部
set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList       - lists configured plugins
" :PluginInstall    - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean      - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line

以上 Vundle 配置我进行了一些修改,因为 Vundle 官网提供的配置文件有一些插件在我的网络环境下无法正常下载,从而导致运行 :PluginInstall 时出现卡死的状况。因此,对于 Vundle 可以根据自己的需要,适当调整添加的插件。

配置好系统的 Python 环境以及 CMake

以下是针对 Ubuntu 系统的环境配置,这里主要需要给系统安装配置好 cmake 以及 python,具体命令如下:

# install CMake
sudo apt-get install build-essential cmake
# install Python
sudo apt-get install python-dev python3-dev

通过 Git Clone 下载 YouCompleteMe

官网文档介绍,YouCompleteMe 是可以通过 Vundle 来安装的,但由于我的网络问题,所以我选择了直接从 GitHub 上下载好文件。方法如下:

# make sure in dir ~/.vim/bundle
cd ~/.vim/bundle
# Download by git clone
git clone https://github.com/Valloric/YouCompleteMe.git

安装 YouCompleteMe

接下来,进入最后的步骤,运行 .install.py 脚本安装语言支持。这里为了方便,我们选择安装所有语言支持,如果需要只安装特定的语言支持,可以参考官方文档。

cd ~/.vim/bundle/YouCompleteMe
./install.py --all

执行完成后,如果没有错误信息提示,那么 YouCompleteMe 即安装配置完成了。

以下是我安装好的 YouCompleteMe 演示的 Python 代码提示:


参考资料

VundleVim/Vundle.vim Valloric/YouCompleteMe

发布于 2018-04-13 11:23