为VIM安装YouCompleteMe插件

YouCompleteMe

YouCompleteMe is a fast, as-you-type, fuzzy-search code completion engine for Vim

据说YouCompleteMe是一个强大的自动补全插件,就试着安装一下,体验后确实不错,但安装过程也不是一帆风顺的,总结一下过程,希望下次再用时不要再跳坑喽。

环境

首先说下我自己的环境,系统是ubuntu16.04 LTS 64位,VIM版本为7.4.1689 -python +python3,VIM安装插件时使用VIM插件管理工具Vundle安装,假设vim已安装vundle插件管理工具(安装vundle也是很简单的,具体步骤请查看vundle官方说明

安装的前提条件

Ensure that your version of Vim is at least 7.4.143 and that it has support for Python 2 or Python 3 scripting.

Inside Vim, type :version. Look at the first two to three lines of output; it should say Vi IMproved X.Y, where X.Y is the major version of >vim. If your version is greater than 7.4, then you're all set. If your version is 7.4 then look below that where it says, Included patches: >1-Z, where Z will be some number. That number needs to be 143 or higher.

  • VIM的版本必须是7.4以上,并且patch大于等于143
    VIM的补丁号怎么查看? 使用vim --version, 然后查看第二行,包含补丁:1-Z,其中的Z即为补丁号
  • VIM必须有python2或python3的支持
    在终端中使用vim --version grep python,如果出现的python或python3前面有+号则满足条件,如果都是-号说明不满足条件,需要自己动手编译vim源码或下载7.4以上的版本。
    也可以在启动vim后使用:version,vim命令来查看,还可以使用:echo has('python') || has('python3'),vim命令查看满足条件不。
  • 安装cmake,build-essential,python-dev,python3-dev依赖
    如果自己系统中没有这些包,需要先安装这些依赖,这些依赖是编译YCM的必要条件
    在ubuntu中可以使用sudo apt-get install cmake build-essential python-dev python3-dev来安装,其余系统可以参考YouCompleteMe插件官方说明
    另外如果在执行YouCompleteMe安装之前没有安装这些依赖,那么会出现错误奥,如fatal error:pyconfig.h No such file or directory

安装

安装的步骤还是很简单的,关键是需要满足前提条件,如果不满足是肯定过不去的。。。

在~/.vimrc的call vundle#end()之前添加Plugin 'Valloric/YouCompleteMe',然后保存,然后执行:source ~/.vimrcvim命令,然后执行:PluginInstallvim命令,最后就是等待VIM下载YouCompleteMe

下载完成后切换到vundle目录下的YouCompleteMe,如本机的
vim-youcompleteme
然后执行./install.py或./install.sh等待安装完成

安装完成后新建一个python文件,然后使用vim编辑一下吧,记得使用C-X C-O体验一下全能补全奥。。。

po一张最后的效果图
vim-youcompleteme2

转载于:https://www.cnblogs.com/guanfeng/p/6837710.html

### 回答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中运行,让您更加高效地进行编码工作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值