Vim 下的自动补全,最好的工具莫过于 YouCompleteMe,官方文档在这里 http://valloric.github.io/YouCompleteMe/

安装稍显复杂,以下记录我的过程。

1. 安装 Vundle

(这里顺带就把 YouCompleteMe 下载了)

Vundle 是 Vim 下的一个插件管理器,如果之前你配置 Vim 是手动放置 xxx.vim 配置文件到相应目录,那么现在你要安装 Vundle, 因为 YouCompleteMe 是基于 Vundle 安装的,

Vundle 的 github 地址: https://github.com/VundleVim/Vundle.vim

- git 克隆插件  $ git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

-  添加如下内容到 ~/.vimrc 文件最前面,

"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ For Vundle Start
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'

" Install YouCompleteMe
Plugin 'Valloric/YouCompleteMe'  " 注意,这就是要安装的插件 YouCompleteMe

" All of your Plugins must be added before the following line
call vundle#end()             " required
filetype plugin indent on     " required

"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ For Vundle End

保存关闭。

-   启动 Vim,执行命令 :PluginInstall 将出现如下安装画面,( YouCompleteMe 插件较大,请耐心等待)

2. 编译 YouCompleteMe

- 安装相关工具

$ sudo apt-get install build-essential cmake

- 安装相关 Python 库

$ sudo apt-get install python-dev python3-dev

- 编译 (为支持 C,C++,Python 智能补全,添加选项 --clang-completer)

cd ~/.vim/bundle/YouCompleteMe

./install.py --clang-completer

注: 为支持其他语言,比如 Javascript,Go 等,要首先安装相应的工具,具体参见官方文档。

3. 设置 .vimrc

“ 配置默认的 .ycm_extra_conf.py 路径
let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/third_party/ycmd/examples/.ycm_extra_conf.py'

注:当有新库加入时,需要更新此文件,例如,我要支持 boost 的补全,则要加入 boost 头文件路径 /usr/local/boost_1_67_0,加到 flags 的最后即可,

flags = [

...

# for boost complete
'-isystem',
'/usr/local/boost_1_67_0'
]

4. 使用中的问题

- 补全功能可用,但是会有恼人的信息,

我当前安装的 gVim 版本是 7.4.52, 根据 YouCompleteMe 官网的建议,升级到 7.4.314 以上可解决这个问题,于是,

# add-apt-repository ppa:pi-rho/dev

# apt-get update

# apt-get install vim-gnome  (重装即可升级)

升级后,问题解决。

注: 补全时,当弹出 tip 窗口,按 Tab 来 cycle 可选项。

另, Centos 升级 gvim 到 8.x 版本见:https://www.cnblogs.com/gaowengang/p/10546815.html

 对于 Ubuntu 18.04 的 workaround 方法  

因为我之前一直用 Ubuntu 14.04 和  CentOS 7,这两个操作系统默认的 gcc 版本是 4.8,我在这两个系统下完成了对 gvim 的各种配置(包括 YouCompleteMe 的配置),并且各项功能都调好了。

因项目需要,在升级系统到 Ubuntu 18.04 后,为方便起见,我把旧系统的 .vimrc 和 .vim 拷贝到新系统的 home 目录下, 并调整 YouCompleteMe 配置文件的内容,使其指向新系统的 c++ 头文件目录,但是却不能实现 c++ 的自动补全。目前怀疑和 Ubuntu 18.04 的 gcc 和 g++ 版本有关,新系统默认的版本是 7.4。

workaround 方法是:安装 gcc 4.8  ( $ sudo apt-get install gcc-4.8 ) 和 g++ 4.8 ( $ sudo apt-get install g++-4.8 ),并调整 YouCompleteMe 配置文件,使其指向 c++ 4.8 的头文件目录。

完。

Vim 安装 YouCompleteMe的更多相关文章

  1. vim安装YouCompleteMe 插件

    要安装YouCompleteMe ,vim须支持python.看是否支持,可以在vim中:version 查看, 如果python前有+号,就是支持,减号就是不支持. 如果不支持,需要以编译安装方式重 ...

  2. 给vim安装YouCompleteMe

    要安装YouCompleteMe ,vim须支持python.看是否支持,可以在vim中:version 查看, 如果python前有+号,就是支持,减号就是不支持. 如果不支持,需要以编译安装方式重 ...

  3. UBuntu14.04 --vim安装YouCompleteMe插件

    说明 我电脑的系统参数(用 uname -a命令查看)如下: Linux avyn-Lenovo --generic #-Ubuntu SMP Tue Mar :: UTC i686 i686 i68 ...

  4. Vim+Vundle+YouCompleteMe 安装

    这段时间在Centos 7上开发c++程序,想为vim安装YouCompleteMe插件,参照几个博客无果,果断上官网找解决方案.功夫不负苦心人,终于搞定. 学习东西还是要多上官网. 下面送上本次的收 ...

  5. vim 安装

    Ubuntu 16.04 下 Vim安装及配置 默认已经安装了VIM-tiny linuxidc@linuxidc:~$ locate vi | grep 'vi$' |xargs ls -al lr ...

  6. Ubuntu16.04安装vim插件YouCompleteMe

    原文 1 下载 git clone --recursive git://github.com/Valloric/YouCompleteMe 如果执行该命令没报错, 就ok了. 但是中途有可能会断掉, ...

  7. 解决安装YouCompleteMe与Vim版本不兼容问题

    用vim 7.4.4版本装YouCompleMe的时候提示这样的信息: YouCompleteMe unavailable: requires Vim 7.4.1578+.明明版本比它要求的还高,居然 ...

  8. Vim中YouCompleteMe插件安装

    背景 YouCompleteMe需要使用GCC进行编译,然而Centos 6.7默认的GCC版本太低,所以需要使用devtools-2,用来安装多个版本GCC手动编译安装GCC的坑简直不要太多(类似于 ...

  9. 【转】ubuntu 12.04 下 Vim 插件 YouCompleteMe 的安装

    原文网址:http://www.cnblogs.com/jostree/p/4137402.html 作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree ...

随机推荐

  1. VMWAR-workstatuon

    https://blog.csdn.net/felix__h/article/details/82853501 链接中的秘钥可用~感谢原文作者 下载安装: 官网下载地址:https://www.vmw ...

  2. jstack 排查 java 进程占用大量 CPU 问题

    1. top 看看哪个进程是罪魁祸首 2.将这个进程的jstack dump 到一个文件里面,以备使用. jstack -l 25886 > /tmp/jstack.log # 如果报错,则加 ...

  3. 一个简单的scrollTop动画的方法

    var autoScrollTop = function (param) { var delay = param.scrollDom.height() * 20; param.dom.animate( ...

  4. Human Motion Analysis with Wearable Inertial Sensors——阅读1

    Human Motion Analysis with Wearable Inertial Sensors——阅读 博主认为对于做室内定位和导航的人这是一篇很很棒的文章,不是他的技术很牛,而是这是一篇医 ...

  5. Gson解析空字符串异常的处理

    面对一些不规范的json,我们的gson解析经常会抛出各种异常导致app崩溃,这里可以采取一些措施来避免. 我们期望在后台返回的json异常时,也能解析成功,空值对应的转换为默认值,如:newsId= ...

  6. go 利用orm简单实现接口分布式锁

    在开发中有些敏感接口,例如用户余额提现接口,需要考虑在并发情况下接口是否会发生问题.如果用户将自己的多条提现请求同时发送到服务器,代码能否扛得住呢?一旦没做锁,那么就真的会给用户多次提现,给公司带来损 ...

  7. [20180918]文件格式与sql_id.txt

    [20180918]文件格式与sql_id.txt --//记录测试中遇到的一个问题.这是我在探究SQL*Net more data from client遇到的问题.--//就是实际oracle会把 ...

  8. C#-类(九)

    类的定义 类是描述具有相同特征与行为的事物的抽象,类内部包含类的特征和类的行为 类支持继承 类的定义是关键字class为标志 类的格式 访问标识符 class 类名 { 类主体 } 访问标识符:指定了 ...

  9. oracle 压力测试工具benchmarksql

    TPC-C测试 TPC-C 于 1992 年 7 月 23 日认可为新的基准测试.TPC(Transaction Processing Performance Council,事务处理性能委员会)-C ...

  10. malloc和calloc用法

    malloc和calloc用法 #include <stdio.h> #include <stdlib.h> int main(){ int n; printf("i ...