天天看点

ubuntu下vim 安装插件管理工具Vundle和自动补全插件YouCompleteMe

ubuntu下vim 安装Vundle和YouCompleteMe

采用的系统硬件都得环境

(1)操作系统:ubuntu14.04(ubuntu16.04也可以用)

(2)vim版本:vim8

前言

对于一个Linux系统,源都是国外的,因此在国内下载软件操作,一定要更新国内的镜像源。然后在进行其他一系列的开发和使用,如果源有问题,就会造成很多软件下载不成功等各种问题。更换成国内的镜像源是非常关键而且必须的一步,为什么同样的操作,在别人的电脑上能执行,而你却不能执行,很有可能就是差在这一步上了。

强烈推荐清华源,下面提供一个ubuntu清华源的官方链接,非常好用,而且可以根据ubuntu的版本选择不同版本的源

(https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/)

ubuntu下vim 安装插件管理工具Vundle和自动补全插件YouCompleteMe

更换完国内源后,按照下面的步骤,一步一步安装YoucompleteMe插件,自动补全功能,非常强大。

1.安装vim8

ubuntu 14.05 安装完YouCompleteMe后不生效,提示:YouCompleteMe unavailable : requires Vim 7.4.143

经过检索与查询,ubuntu自带的vim为7.4.50,需要安装最新的vim。按照下面的指令,进行vim8的下载。

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

2.Vundle安装及配置

(1)安装git

sudo apt-get install git
           

(2)将Vundle克隆至本地用户根目录下的~/.vim/bundle路径下,若无该路径可自行建立

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

(3)配置Vundle的插件

将以下内容放至.vimrc文件的顶部,若无.vimrc文件,可在用户主目录下创建.vimrc文件,即~/.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'

" My Plugins:
Plugin 'Valloric/YouCompleteMe'

" 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的安装和配置文件的设置已经完成。

3.YouCompleteMe安装

我们已经采用的vim8了,可以再次确认一下vim版本以及是否支持Python2/3,YouCompleteMe需要VIM7.4.1578及以上版本和Python2/3的支持,安装YouComplete前请一定确认自己的VIM版本,以及VIM是否支持Python2/3,可在终端输入以下指令查看

vim --version
           
ubuntu下vim 安装插件管理工具Vundle和自动补全插件YouCompleteMe

(1)安装cmake和相关Python头文件

YouCompleteMe的安装需要cmake和python相关头文件的支持,可在终端下通过如下命令安装:

sudo apt-get install build-essential cmake
sudo apt-get install python-dev python3-dev
sudo apt-get install clang
           

(2)YouCompleteMe的安装

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

载完成后,需要对YouComplete进行编译安装

cd ~/.vim/bundle/YouCompleteMe
./install.py --clang-completer
           

发现命令无法执行,会提示执行下面指令,输入执行

git submodule update --init --recursive
           
ubuntu下vim 安装插件管理工具Vundle和自动补全插件YouCompleteMe

这个过程得至少半小时,耐心等待,只要没有提示错误,会一直进行,就ok

(3)编译

cd ~/.vim/bundle/YouCompleteMe
./install.py --clang-completer
           
ubuntu下vim 安装插件管理工具Vundle和自动补全插件YouCompleteMe
ubuntu下vim 安装插件管理工具Vundle和自动补全插件YouCompleteMe
ubuntu下vim 安装插件管理工具Vundle和自动补全插件YouCompleteMe

那个error,不影响操作

4.YouCompleteMe配置

(1)编译完成之后,还需要进行一些配置工作。把

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

这个文件复制到

~/.vim

目录下面

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

(2)在~/.vimrc配置文件中还需添加如下配置。

let g:ycm_server_python_interpreter = '/usr/bin/python'
let g:ycm_global_ycm_extra_conf ='~/.vim/.ycm_extra_conf.py'
           

这样就完成了YouCompleteMe插件的安装和配置

5.测试

(1)建立一个test.c文件

touch test.c
           

(2)用vi打开

ubuntu下vim 安装插件管理工具Vundle和自动补全插件YouCompleteMe

指针也ok

ubuntu下vim 安装插件管理工具Vundle和自动补全插件YouCompleteMe

注:

很多博客和书上都是以下面的方式下载YouCompleteMe。

首先打开vim,在其界面输入如下指令进行YouCompleteMe的下载

:PluginInstall
           

下载完成后,会出现”Done!“。这一步的操作与网络有很大的关系,所以在操作前,务必确保网络的通畅。下载完成后,需要对YouComplete进行编译安装。本文只考虑对C++的自动补全,因此进入终端输入如下指令

cd ~/.vim/bundle/YouCompleteMe
./install.py --clang-completer
           

因为在vim下执行PluginInstall,没有进程的反应,所以根本不知道是在下载还是卡机了,而且我测试了一晚上还是没有下载成功,所以还是建议上面的方法。

参考资料:

1.https://blog.csdn.net/ZeroDegree1216/article/details/81950656

2.https://blog.csdn.net/u011529752/article/details/78462125

继续阅读