【YouCompleteMe】Ubuntu下YouCompleteMe安装

本文详细介绍如何在Ubuntu环境下安装并配置Vim补全插件YouCompleteMe,包括安装Vim、Vundle插件管理工具、下载YouCompleteMe及添加C/C++语言支持,解决常见安装问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ycm是一款vim补全插件,装上插件后利用vim开发时可以自动补全。以下是安装步骤

1.安装vim

sudo apt-get install vim

2.安装vim插件管理工具Vundle

可以去GitHub查看官方文档如何安装。

git clone https://github.com/gmarik/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'

" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.

" 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

然后使用:PluginInstall命令 就可以开始用Vundle进行管理了。

添加begin/end之间添加PluginInstall ‘Valloric/YouCompleteMe’,保存后,再执行命令:PluginInstall就可以开始安装YouCompleteMe了。

但是我在下载的时候经常就卡住不动了,需要等很长时间。所以建议先把ycm直接下载在~/.vim/bundle/下。

3.下载YouCompleteMe

git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle  
git clone https://github.com/Valloric/YouCompleteMe.git ~/.vim/bundle/YouCompleteMe  
cd ~/.vim/bundle/YouCompleteMe  
git submodule update --init --recursive 

下载完成后,安装插件

vim
:PuginInstall

此时安装就会很快

4.添加语言支持(c和c++语言支持)

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

修改~/.vimrc文件,将以下内容加入

let g:ycm_global_ycm_extra_conf = ‘~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py’       "配置全局路径
let g:ycm_confirm_extra_conf=0   "每次直接加载该文件,不提示是否要加载

同时要补全语言,要对~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py进行修改:
在flags下添加(如果有相关内容只需把相应版本改为Ubuntu内装的版本)

'-isystem',
 '/usr/include',
 '-isystem',
'usr/include/c++/5.4.0'
'-isystem',
'usr/include/x86_64-linux-gnu/c++',

5.缺少~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py文件的办法

安装完后发现~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py文件不存在,直接自己创建将如下内容写入即可

import os
import ycm_core
 
flags = [
    '-Wall',
    '-Wextra',
    '-Werror',
    '-Wno-long-long',
    '-Wno-variadic-macros',
    '-fexceptions',
    '-DNDEBUG',
    '-std=c++11',
    '-x',
    'c++',
    '-I',
    '/usr/include',
    '-isystem',
    '/usr/lib/gcc/x86_64-linux-gnu/5/include',
    '-isystem',
    '/usr/include/x86_64-linux-gnu',
    '-isystem'
    '/usr/include/c++/5',
    '-isystem',
    '/usr/include/c++/5/bits'
  ]
 
SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', ]
 
def FlagsForFile( filename, **kwargs ):
  return {
    'flags': flags,
    'do_cache': True
  }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值