1.环境

本文使用VMWare虚拟机进行实验,客户机系统是CentOS 7.2最小安装(CentOS-7-x86_64-Minimal-1511.iso)

最终实现效果:安装vim8 + python2.7(自带)+ ycm,实现C/C++的智能提示、补全、跳转。

2.需求

  • Git
  • GCC
  • CMake(3.10以上)
  • Vim
  • Vundle
  • YouCompleteMe
  • 各种依赖库

3.安装

3.1 下载安装必要的组件

yum install -y gcc gcc-c++ ruby ruby-devel lua lua-devel  \
ctags git python python-devel \
tcl-devel ncurses-devel \
perl perl-devel perl-ExtUtils-ParseXS \
perl-ExtUtils-CBuilder \
perl-ExtUtils-Embed

3.2 安装Vim8

访问https://github.com/vim/vim/releases,下载最新的release版本,我这里是vim-8.0.1645.tar.gz

然后解压配置编译安装

tar zxvf vim-8.0..tar.gz
cd vim-8.0. ./configure --with-features=huge \
--enable-multibyte \
--enable-rubyinterp=yes \
--enable-pythoninterp=yes \
--with-python-config-dir=/usr/lib64/python2./config \
--enable-perlinterp=yes \
--enable-luainterp=yes \
--enable-cscope \
--prefix=/usr/local make VIMRUNTIMEDIR=/usr/local/share/vim/vim80
make install

注意: --with-python-config-dir这项要看自己的实际路径,是python-devel带的目录

更改下系统编辑器

sudo update-alternatives --install /usr/bin/editor editor /usr/local/bin/vim
sudo update-alternatives --set editor /usr/local/bin/vim
sudo update-alternatives --install /usr/bin/vi vi /usr/local/bin/vim
sudo update-alternatives --set vi /usr/local/bin/vim

3.3 安装YouCompleteMe

3.3.1 下载Vundle

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

配置~/.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'
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

3.3.2 下载YouCompleteMe

打开vim,输入如下命令

:PluginInstall

注意:这里很考验网速,可能会比较慢,下载好后,整个.vim文件夹大约150~250MB(根据时间版本不同)。

3.3.3 下载CMake(yum安装的2.8版本不行)

访问https://cmake.org/download/,我这里是cmake-3.10.3.tar.gz

解压编译安装

tar zxvf cmake-3.10..tar.gz
cd cmake-3.10.
./bootstrap && make && make install

3.3.4 编译YouCompleteMe(支持C/C++)

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

编译完成后,整个.vim文件夹大约350MB。

注意:如果使用--clang-completer选项,脚本会判断当前是否有upstream pre-build libclang.so库(不建议用系统的libclang):

如果有则用缓存的(见缓存位置);如果没有则会去下载库(见下载地址)。

看网络状况,可能会下载不全(sha256值不对),导致下面编译YouCompleteMe时出错。可以先用迅雷下载,再替换过去。

下载地址:https://dl.bintray.com/micbou/libclang/libclang-6.0.0-x86_64-linux-gnu-ubuntu-14.04.tar.bz2

缓存位置:.vim/bundle/YouCompleteMe/third_party/ycmd/clang_archives/

3.3.5 配置YouCompleteMe

编辑~/.vimrc,增加以下内容

let g:ycm_global_ycm_extra_conf='~/.ycm_extra_conf.py'  "设置全局配置文件的路径
let g:ycm_seed_identifiers_with_syntax= " 语法关键字补全
let g:ycm_confirm_extra_conf= " 打开vim时不再询问是否加载ycm_extra_conf.py配置
let g:ycm_key_invoke_completion = '<C-a>' " ctrl + a 触发补全,防止与其他插件冲突
set completeopt=longest,menu "让Vim的补全菜单行为与一般IDE一致(参考VimTip1228)
nnoremap <leader>jd :YcmCompleter GoToDefinitionElseDeclaration<CR> "定义跳转快捷键

第一行所需的.ycm_extra_conf.py,可以从自带的复制一份过来,再根据需要进行配置

cp .vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py ~

4.运行

现在运行vim已经可以对C++进行提示补全了(因为刚才是从cpp子目录下拷贝的配置样例),

打开~/.ycm_extra_conf.py可以看到其中flags变量,就是配置项目代码补全提示的

比如(C++项目)

flags = [
'-Wall',
'-Wextra',
'-Werror',
'-fexceptions',
'-DNDEBUG',
'-std=c++11',
'-x',
'c++',
'-isystem',
'/usr/include',
'-isystem',
'/usr/local/include',
'-I',
'/root/my_proj',
]

如果是C项目,需要调整

-std=c99,-x下面的参数改为c。

解析C/C++相关的符号提示(系统的、三方库的、自己的),需要配置-isystem,'-I',参数为头文件所在目录。

配置好后,用vim编辑一个C文件,

输入#include<会自动弹出提示窗

结构体输入.时会提示成员,

结构体指针输入->时会提示成员

YouCompleteMe默认不会像IDE那样主动提示符号补全(如输入pri提示printf),想要补全时按Ctrl+A(见上面配置)。

以上弹出提示窗,按Ctrl+N、Ctrl+P上下选择补全。

符号跳转

光标定位到需要跳转的符号上,输入\jd(\是默认leader),实现跳转(该跳转有条件,不一定100%成功,可见官网说明

在printf上按\jd,跳转到定义

按Ctrl+o跳回之前的位置。

5.其他

实际使用每个项目单独一个.ycm_extra_conf.py配置,GitHub上有个项目可以自动生成配置文件, 有需要可以参考下。

CentOS7.2安装Vim8和YouCompleteMe的更多相关文章

  1. Centos7安装vim8.0 + YouCompleteMe

    更新yum sudo yum upgrade sduo yum update 下载git sudo yum install git 升级vim以及gcc 升级gcc sudo yum install ...

  2. 学以致用八---centos7.2 安装vim8+支持python3

    目的:打造基于python的vim环境 也是在地铁上突然产生的一个想法,平时都是在pycharm上练习python,但有时候会提示激活码过期,又得上网找激活码,够折腾的.那何不在linux环境下来搭建 ...

  3. ubuntu16.04下编译安装vim8.1

    之前写过一篇centos7下编译安装vim8.0的教程,ubuntu16.04相比centos7下安装过程不同在于依赖包名字的不同,其余都是一样.下面给出ubuntu16.04编译安装vim8.0需要 ...

  4. Ubuntu16.04安装vim8

    Ubuntu16.04安装vim8 在Ubuntu16.04下编译安装vim8,并配置vim-plug插件管理器,以及安装YouCompleteMe等插件. 安装依赖 sudo apt-get ins ...

  5. Ubuntu 16.04安装Vim8.0

    Ubuntu 16.04安装Vim8.0 https://www.aliyun.com/jiaocheng/131859.html sudo add-apt-repository ppa:jonath ...

  6. 在centos7上安装Jenkins

    在centos7上安装Jenkins 安装 添加yum repos,然后安装 sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins ...

  7. CentOS7 Jenkins安装

    CentOS7 Jenkins安装 CentOS7 Jenkins安装 Download 从Jenkins下载apache-tomcat-8.0.18.tar.gz Install 安装 上传RPM文 ...

  8. 在 CentOS7 上安装 zookeeper-3.4.9 服务

    在 CentOS7 上安装 zookeeper-3.4.9 服务 1.创建 /usr/local/services/zookeeper 文件夹: mkdir -p /usr/local/service ...

  9. 在 CentOS7 上安装 MongoDB

    在 CentOS7 上安装 MongoDB 1 通过 SecureCRT 连接至 CentOS7 服务器: 2 进入到 /usr/local/ 目录: cd /usr/local 3 在当前目录下创建 ...

随机推荐

  1. c/s委托练习

    今天玩了玩C/S开发,也随便练习了很久不用的委托 父窗体中写的代码 #region 委托与事件传递    public delegate void TextChangedHandler(string ...

  2. hdu 5040 Instrusive【BFS+优先队列】

    11733274 2014-09-26 12:42:31 Accepted 5040 62MS 1592K 4848 B G++ czy 先转一个优先队列的用法: http://www.cppblog ...

  3. 一起来学Spring Cloud | 第五章:熔断器 ( Hystrix)

    在微服务项目中,一个系统可以分割成很多个不同的服务模块,不同模块之间我们通常需要进行相互调用.springcloud中可以使用RestTemplate+Ribbon和Feign来调用(工作中基本都是使 ...

  4. [bzoj1187][HNOI2007]神奇游乐园_插头dp

    bzoj-1187 HNOI-2007 神奇游乐园 题目大意:经历了一段艰辛的旅程后,主人公小P乘坐飞艇返回.在返回的途中,小P发现在漫无边际的沙漠中,有一块狭长的绿地特别显眼.往下仔细一看,才发现这 ...

  5. Linux最常用的命名

    一.环境配置 vim /etc/sysconfig/network-scripts/ifcfg-eth0 vim /etc/sysconfig/network vim /etc/hostname vi ...

  6. Ubuntu 16.04安装微信

    微信没有出Linux的版本,但是可以通过以下方式解决: 1.使用网页版,除了没有公众号之后,一切都没问题,包括传文件等. 网页登录地址:https://wx.qq.com/ 2.使用第三方版本,只不过 ...

  7. pinpoint 应用性能管理工具安装部署

    原文:http://www.cnblogs.com/yyhh/p/6106472.html pinpoint 安装部署   阅读目录 1. 环境配置 1.1 获取需要的依赖包 1.2 配置jdk1.7 ...

  8. PPAPI+Skia实现的涂鸦板

    在PPAPI插件中使用Skia画图介绍了怎样在PPAPI中使用Skia,文末说回头要提供一个简单的涂鸦板插件,这次我来兑现承诺了. foruok原创,关注微信订阅号"程序视界"可联 ...

  9. Coursera 机器学习Course Wiki Lecture Notes

    https://share.coursera.org/wiki/index.php/ML:Main 包含了每周的Lecture Notes,以便复习回顾的时候使用.

  10. TFTP服务器

    为什么要学习有关TFTP服务器的安装及配置呢?主要是为了后续学习有关linux系统的无人值守安装做准备. TFTP简单文件传输协议,使用UDP的69端口.主要提供文件的上传和下载,TFTP一般是适用于 ...