Ubuntu下安装YouCompleteMe插件

YouCompleteMe被誉为是vim自动补全神器,它是依附于vim的插件,支持多语言补全功能,包括了:C,C++,Python等

废话少说,直接进入正题吧,在网上看了很多安装的教程,但是很多已经过时了,安装不能成功,所以自己总结了一下。

说实话,我也不太清楚每个步骤是否必要,但是亲测可用,不对的地方希望读者指出。

因为Ubuntu系统默认安装了python所以不需要再进行安装,输入:vim  在非输入状态下输入::version 确认是否有python即可,“+”则证明支持


安装准备:

需要cmake,如果未安装,输入: sudo apt-get install  cmake

确保python头文件已安装,输入: sudo apt-get install python-dev


之后安装vundle插件,输入:git clone https://github.com/gmarik/vundle.git  ~/.vim/bundle/vundle

如果在.vim/目录下没有bundle文件夹新建一个即可(输入:mkdir bundle)


之后将下面这段代码加入你的.vimrc文件最后(如果没有.vimrc文件,新建即可)

set nocompatible              " be iMproved, required
filetype off                  " required

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

" let Vundle manage Vundle, required
Plugin 'gmarik/vundle'

" The following are examples of different formats supported.
" Keep Plugin commands between here and filetype plugin indent on.
" scripts on GitHub repos
Plugin 'tpope/vim-fugitive'
Plugin 'Lokaltog/vim-easymotion'
Plugin 'tpope/vim-rails.git'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" scripts from http://vim-scripts.org/vim/scripts.html
Plugin 'L9'
Plugin 'FuzzyFinder'
" scripts not on GitHub
Plugin 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own plugin)
Plugin 'file:///home/gmarik/path/to/plugin'
" ...

filetype plugin indent on     " required
Bundle 'Valloric/YouCompleteMe'

保存退出之后,输入:vim,在非输入状态下输入: :BundleInstall  之后便进行自动安装



如果上述步骤一切正常,没有报错,则安装完成(当然这种情况真的是不可能发生,至少我是一大堆错误)

报错一:

Taglist: Exuberant ctags (http://ctags.sf.net) not found in PATH. Plugin is not loaded.

请按 ENTER 或其它命令继续

这个错误实在打开vim时,终端报出,按下回车即可进入vim

解决方法:

输入:vim  .vimrc  在最后一行加入  let Tlist_Ctags_Cmd = '/usr/local/bin/ctags'   保存退出



报错二:

Done! With errors; press l to view log
ycm_client_support.[so|pyd|dll] and ycm_core.[so|pyd|dll] not detected; you need
to compile YCM before using it. Read the docs!

这一步是在输入:BundleInstall之后,安装 Plugin 'git://git.wincent.com/command-|~失败后报出的错误

解决方法:

到 .vim/bundle/YouCompleteMe 下 ,输入:./install.py --clang-completer


如果还报错,应该是报的:

Some folders in /home/sky-tm/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party are empty; you probably forgot to run: git submodule update --init --recursive

解决方法:

直接输入:git submodule update --init --recursive

完成之后再输入:./install.py --clang-completer


最倒霉的就是还报错:(这个错误我自己没有遇见,只是看见有人说报过这个错误,包括解决方法一样是看的别人的,没有亲测过)

Your C++ compiler supports C++11, compiling in that mode.
Downloading Clang 3.5
CMake Error at ycm/CMakeLists.txt:62 (message):
No pre-built Clang 3.6 binaries for 32 bit linux. You'll have to compile
Clang 3.6 from source. See the YCM docs for details on how to use a
user-compiled libclang.

解决方法:

直接输入:./install.sh --clang-completer --system-libclang 

完成之后再输入:./install.py --clang-completer

这下应该没有错误了才对


报错三:

No .ycm_extra_conf.py file detected, so no compile flags are available. Thus no semantic support for C/C++/ObjC/ObjC++.

这个错误同样是在打开vim的时候报出的,但是只在终端最下方,红色字体显示,需要注意。不过如果发现c/c++无法补全就知道出问题了

解决方法:

在~/.vim/bundle/YouCompleteMe/third_party/ycmd 文件下将 cpp文件夹考到 .vim/bundle/YouCompleteMe 文件下

输入:cp -r cpp/   .vim/bundle/YouCompleteMe   再次打开就可以正常使用了



至此,这个vim自动补全神器就安装完成了。之后使用vim编译python,c++等语言的时候,根据设置的文件后缀不一样会自动补全。

如果本文中有不对的地方希望各位读者留言指出,我会尽快修改,谢谢!!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值