vim插件——YouCompleteMe


  版权声明:本文参考了《YouCompleteMe 官方文档》未经作者允许,严禁用于商业出版,否则追究法律责任。网络转载请注明出处,这是对原创者的起码的尊重!!!


1 简介

  • 插件介绍:YouCompleteMe是一款针对Vim的快速,即用型的模糊搜索代码补全引擎。包括以下几种引擎:
    • 基于标识符的引擎,可与每种编程语言一起使用
    • 基于Clang的引擎,为C / C ++ / Objective-C / Objective-C ++(C系列)提供本地语义代码补全
    • 基于Jedi的Python 2和3的补全引擎
    • 基于OmniSharp的C#补全引擎
    • Go的GocodeGodef语义引擎的组合,
    • 基于TSServer的TypeScript完成引擎,
    • 基于Tern的JavaScript补全引擎,
    • 基于racer的Rust补全引擎,
    • 基于jdt.ls的Java实验性补全引擎。
    • 基于omnifunc的补全引擎,它使用来自Vim的omnicomplete系统的数据为许多其他语言(Ruby,PHP等)提供语义补全。
    • 基于UltiSnips的代码片补全引擎
  • 仓库地址https://github.com/Valloric/YouCompleteMe

2 安装(Ubuntu 16.04)

  • 首先确保Vim版本至少为7.4.1578,并且支持Python 2或Python 3。
    • vim --version | grep python,显示+python则支持,否则安装支持python2的vim-nox-py2,或者使用源码重新编译vim
  • 使用Vundle安装YCM,以支持python2或python3
    • git clone https://github.com/Valloric/YouCompleteMe.git ~/.vim/bundle/YouCompleteMe
    • cd ~/.vim/bundle/YouCompleteMe
    • git submodule update --init --recursive
    • vim ~/.vimrc
    • call vundle#begin()call vundle#end()之间添加Plugin 'Valloric/YouCompleteMe'
    • :wq
    • vim
    • :PluginInstall
  • 安装编译环境
    • sudo apt install build-essential cmake
    • sudo apt install python-dev python3-dev
    • sudo apt install ctags
    • sudo apt install gcc g++
    • sudo apt install clang libclang-dev
  • 编译YCM
    • cd ~/.vim/bundle/YouCompleteMe
    • ./install.py
    • 语言支持:
      • C/C++/Objective-C/Objective-C++:编译时添加--clang-completer
      • C#:先安装Mono,编译时添加--cs-completer
      • Go:先安装Go,编译时添加--go-completer
      • TypeScript:先安装 Node.js and npm,然后使用npm install -g typescript安装TypeScript SDK
      • JavaScript: 先安装 Node.js and npm,编译时添加--js-completer
      • Rust: 先安装Rust,编译时添加--rust-completer
      • Java: 先安装JDK8,编译时添加--java-completer
      • 全部支持:先安装所有的依赖环境,编译时添加--all

注意:如果提示fatal: unable to access 'https://go.googlesource.com/tools/': Failed to connect to go.googlesource.com 那就是GFW做的,自己想办法吧

3 C族语义补全配置

  • vim ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/.ycm_extra_conf.py
  • 在flags[]列表中添加头文件路径,编译选项:
'-isystem',
'C/C++ 头文件绝对路径',
'-I',
'C/C++ 头文件绝对路径',
'-std',
'C/C++ 标准',
'-x',
'目标语言',
  • 如果不想因为c++11新特性发出警告就添加’-Wc

  • 11
    点赞
  • 60
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 6
    评论
### 回答1: Vim YouCompleteMe插件安装步骤如下: 1. 安装Vundle插件管理器,可以通过以下命令进行安装: git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim 2. 在.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() " let Vundle manage Vundle, required Plugin 'VundleVim/Vundle.vim' " YouCompleteMe插件 Plugin 'Valloric/YouCompleteMe' " All of your Plugins must be added before the following line call vundle#end() " required filetype plugin indent on " required 3. 打开Vim,运行以下命令进行插件安装: :PluginInstall 4. 安装完成后,进入YouCompleteMe插件目录,运行以下命令进行编译: cd ~/.vim/bundle/YouCompleteMe ./install.py --clang-completer 5. 编译完成后,重新打开Vim即可使用YouCompleteMe插件。 ### 回答2: Vim YouCompleteMeVim编辑器的一个强大的自动补全插件,它可以在你输入时提供不同类型的自动完成选项,如变量名、函数名、类名等。它支持多种编程语言,包括C、C++、Python、JavaScript等。下面是如何安装YouCompleteMe插件。 1.安装vim插件管理器Vundle:从https://github.com/VundleVim/Vundle.vim下载最新的Vundle源代码。将下载的文件解压,并将其放置在~/.vim/bundle/Vundle.vim目录下; 2.加载YouCompleteMe插件:在vim配置文件(.vimrc)中,添加以下代码: `set rtp+=~/.vim/bundle/Vundle.vim` `call vundle#begin()` `Plugin 'Valloric/YouCompleteMe'` `call vundle#end()` 3.编译YouCompleteMe插件:执行以下命令来编译YouCompleteMe: `cd ~/.vim/bundle/YouCompleteMe` `./install.py --clang-completer`(如果你想支持其他语言,可以在安装时使用其他的选项) 4.重启Vim:重新启动Vim。 5.开启YouCompleteMe插件:在命令模式下,执行以下命令来开启YouCompleteMe插件: `:PluginInstall` 6.设置YouCompleteMe插件:在vim配置文件(.vimrc)中,添加以下代码来设置YouCompleteMe插件: `let g:ycm_min_num_of_chars_for_completion=2` `let g:ycm_autoclose_preview_window_after_completion=1` `let g:ycm_collect_identifiers_from_tags_files=1` `let g:ycm_complete_in_comments_and_strings=1` 以上是YouCompleteMe插件的安装步骤及设置方法,希望对您有所帮助。 ### 回答3: 1. 安装vim 在开始安装youcompleteme插件之前,必须确保vim已经被正确地安装在您的电脑上。对于Ubuntu和Debian用户,可以使用以下命令来安装: ``` sudo apt-get install vim ``` 2. 安装Vundle Vundle是一个用于管理vim插件的工具。在安装youcompleteme之前,我们需要先安装Vundle。可以使用以下命令来安装: ``` git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim ``` 3. 安装youcompleteme 安装youcompleteme需要先确保一些依赖项已经被安装在您的电脑上。对于Ubuntu和Debian用户,可以使用以下命令来安装: ``` sudo apt-get install build-essential cmake python-dev python3-dev ``` 在安装完这些依赖项之后,我们需要进入vim并使用Vundle安装youcompleteme插件。 首先,在命令行上输入vim并按回车键,进入vim。 其次,在vim中,按下"Esc"键来进入命令模式。 然后,输入以下命令,以从您的vimrc文件中安装youcompleteme插件: ``` :PluginInstall ``` 在您输入该命令后,Vundle将开始下载并安装youcompleteme插件。此时需要安装此插件的依赖项,输入以下命令: ``` cd ~/.vim/bundle/YouCompleteMe python install.py --clang-completer ``` 这将花费一些时间来完成youcompleteme插件的安装。 4. 配置youcompleteme 安装youcompleteme后,您需要在.vimrc文件中进行一些配置。例如,您可以设置允许youcompleteme在打开文件时立即启动自动补全。添加以下设置: ``` autocmd InsertEnter * if !&completefunc | setlocal completefunc=YouCompleteMe\|UltiSnips#Complete | endif ``` 完成上述步骤后,youcompleteme插件将在您的vim中运行,让您更加高效地进行编码工作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蓝月心语

你的鼓励是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值