Vundle简介与核心功能
前言
毫无疑问,Vim 是一款功能强大的通用文本处理工具,适用于管理系统配置文件及编写代码。借助插件机制,Vim 的功能可以得到多层次拓展。通常情况下,所有插件及其附属配置文件均存放于 ~/.vim 目录中。由于所有插件文件共享同一存储路径,随着插件数量的增加,不同插件的文件间极易产生混淆,导致跟踪和管理变得异常困难。而 Vundle 正是为了解决这一痛点而生。Vundle 取自 Vim 和 Bundle 的首字母缩写,是一款实用的 Vim 插件管理工具。
Vundle 会为每个已安装的插件构建独立的目录结构,并将相关配置文件存储于对应的插件目录内,从而避免文件间的相互干扰。简而言之,Vundle 支持安装新插件、配置现有插件、更新插件设置、检索已安装插件以及清理无用插件等功能。所有这些操作均可通过一键交互模式完成。本教程将指导读者如何在 GNU/Linux 环境中安装 Vundle,并利用其管理 Vim 插件。
Vundle简介
Vundle 全称为 Vim bundle,是一款专门用于管理 Vim 插件的工具。
Vundle 允许你做…
- 在 .vimrc 文件中跟踪和管理插件
- 安装特定格式的插件(即 scripts/bundle)
- 更新特定格式的插件
- 根据插件名称在 Vim scripts 中搜索插件
- 清理未使用的插件
- 以上操作均可通过单一按键完成
Vundle 安装
假设你的系统中已经安装了 Vim。若尚未安装,请同时安装 Vim 和 git(用于下载 Vundle)。这两个软件包通常包含在大多数 GNU/Linux 发行版的官方仓库中。例如,在 Debian 系列系统中,可以使用以下命令安装这两个包。
sudo apt-get install vim git
下载 Vundle
复制 Vundle 的 GitHub 仓库地址:
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
配置 Vundle
创建 ~/.vimrc 文件,以告知 Vim 使用新的插件管理器。该文件对于安装、更新、配置和移除插件至关重要。
vim ~/.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. " plugin on GitHub repo Plugin 'tpope/vim-fugitive' " plugin from http://vim-scripts.org/vim/scripts.html " Plugin 'L9' " Git plugin not hosted 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' " 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/'} " Install L9 and avoid a Naming conflict if you've already installed a " different version somewhere else. " Plugin 'ascenator/L9', {'name': 'newL9'} " 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 " " Brief help " :PluginList - lists configured plugins " :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate " :PluginSearch foo - searches for foo; append `!` to refresh local cache " :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal " " see :h vundle for more details or wiki for FAQ " Put your non-Plugin stuff after this line
标记为 “required” 的行是 Vundle 运行所必需的配置项。其余行仅为示例。如果不需要安装这些特定插件,可以将其删除。完成后,输入 :wq 保存并退出。
最后,打开 Vim 编辑器:
vim
然后输入以下命令来安装插件:
:PluginInstall

此时会弹出一个新的分窗口,之前在 .vimrc 文件中列出的所有插件都将自动开始安装。

安装过程结束后,输入以下命令以清除高速缓存区并关闭窗口:
:bdelete
你也可以直接在终端中使用以下命令安装插件,无需启动 Vim:
vim +PluginInstall +qall
使用 fish shell 的用户,需在 .vimrc 文件中添加以下行。
set shell=/bin/bash
使用 Vundle 管理 Vim 插件
添加新的插件
首先,使用以下命令搜索可用的插件:
:PluginSearch
若要刷新来自 vimscripts 网站的本地列表,请在命令后添加 !。
:PluginSearch!
这将弹出一个列出可用插件的新分窗口:

你还可以通过直接指定插件名的方式来缩小搜索范围。
:PluginSearch vim
这样将会列出包含关键词 “vim” 的插件。
当然也可以指定确切的插件名,例如:
:PluginSearch vim-dasm
将焦点移动到目标行上,按下 i 键即可安装该插件。选中的插件将被安装。
类似地,在系统中安装所有需要的插件。安装成功后,使用以下命令删除 Vundle 缓存:
:bdelete
现在插件已安装完毕。为了让插件正确自动加载,我们需要在 .vimrc 文件中添加已安装插件的名称。 操作方法如下:
:e ~/.vimrc
添加这一行:
[...]
Plugin 'vim-dasm'
[...]
将 vim-dasm 替换为你自己的插件名。然后按 ESC 键,输入 :wq 保存退出。
请注意,所有插件都必须在 .vimrc 文件中追加如下内容。
[...]
filetype plugin indent on
列出已安装的插件
输入以下命令列出所有已安装的插件:
:PluginList

更新插件
输入以下命令更新插件:
:PluginUpdate
输入以下命令重新安装所有插件:
:PluginInstall!
卸载插件
首先,列出所有已安装的插件:
:PluginList
之后将焦点置于正确的一行上,按下 SHITF+d 组合键。

然后编辑你的 .vimrc 文件:
:e ~/.vimrc
删除对应的插件入口。最后,输入 :wq 保存退出。
或者,你可以通过移除 .vimrc 文件中的插件行,并执行以下命令来卸载插件:
:PluginClean
此命令将移除所有不在 .vimrc 文件中但存在于 bundle 目录中的插件。
至此,你应该已经掌握了 Vundle 管理插件的基本方法。在 Vim 中使用以下命令查询帮助文档,获取更多细节。
:h vundle
以上就是所有内容。很快,我将发布下一篇教程。请保持关注!
干杯!
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对本站的支持。
资源
Vundle GitHub 仓库