Vundle.vim 完全指南:在 `.vimrc` 中管理 Vim 插件的安装、更新、搜索与清理

Vundle.vim 完全指南:在 `.vimrc` 中管理 Vim 插件的安装、更新、搜索与清理 开发工具包管理器【免费下载链接】Vundle.vimVundle, the plug-in manager for Vim项目地址https://gitcode.com/gh_mirrors/vu/Vundle.vim点击查看免费下载导读VundleVim bundle 的缩写是一款纯 Vimscript 实现的 Vim 插件管理器它把插件管理这件原本繁琐的工作收拢到.vimrc一个文件之内你可以直接在.vimrc中用Plugin命令声明插件清单由 Vundle 负责克隆安装、更新、按名字搜索 Vim Scripts 仓库、清理不再使用的插件并自动维护运行时路径runtimepath与帮助标签helptags。读完本文你将掌握 Vundle 的完整配置语法、六种:Plugin*命令的用法与 bang 变体、交互式按键映射以及其底层基于 Git 与 Vim runtimepath 的工作机制从而在自己的 Vim 环境中建立一套可复现、可维护的插件体系。1. Vundle 能做什么Vundle 允许你在.vimrc中跟踪并配置你的插件即 scripts/bundle安装已配置的插件更新已配置的插件按名称搜索所有可用的 Vim Scripts清理不再使用的插件通过交互模式用单个按键完成以上所有操作。Vundle 自动完成两件底层工作管理已安装脚本的运行时路径runtimepath在安装与更新后重新生成帮助标签helptags。其搜索功能基于 vim-scripts.org 的脚本数据库见 scripts.vim 中的s:fetch_scripts()实现它从http://vim-scripts.org/api/scripts.json拉取脚本清单。2. 快速开始从安装到第一个插件2.1 环境前提安装要求系统具备GitVundle 会对每个配置的仓库执行git clone默认克隆到~/.vim/bundle/目录搜索功能需要Curl源码中还兼容 wget见 scripts.vim若两者都缺失会报错curl or wget is not availableWindows 用户请参考仓库 Wiki 的 Windows 安装说明遇到问题可查阅 FAQ使用 Fish 等非 POSIX shell 需要额外配置常见做法是在.vimrc中加入set shell/bin/bash。2.2 安装 Vundle 本体git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim2.3 在.vimrc中配置插件将以下内容放在.vimrc顶部。注释中标注了required的行不可省略示例插件可按需删除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 youve 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关于vundle#begin()/vundle#end()的底层行为源码中有明确的实现依据autoload/vundle.vim 中vundle#begin()会设置g:vundle#lazy_load 1延迟修改 runtimepath直到vundle#end()调用vundle#config#activate_bundles()时一次性把所有已配置插件的路径加入 runtimepath 并做默认顺序调整见 config.vim。这就是 changelog 中 #418 Deferred rtp manipulation (speeds up start) 所描述的启动加速机制。仓库自带的 test/minirc.vim 就是一份最精简的最小配置set nocompatible syntax on filetype off set rtp~/.vim/bundle/Vundle.vim/ call vundle#begin() Plugin VundleVim/Vundle.vim call vundle#end() filetype plugin indent on2.4 安装插件启动vim后运行:PluginInstall也可以直接在命令行完成安装并退出vim PluginInstall qall新安装的插件会被自动激活加入 runtimepath 并 sourcing但个别插件可能还需要额外步骤如编译或外部程序请参阅插件自身的文档。3. 深入配置Plugin 命令与支持格式3.1 Plugin 命令的工作方式Vundle 通过.vimrc中的Plugin命令跟踪你想要配置的插件。每条Plugin命令都会在启动时把对应脚本加入 runtimepath。注释掉或删除该行即可禁用对应插件。注意Plugin命令所在行不允许在命令后追加注释。Plugin命令的第一个参数是一个 URI还可以紧跟一个可选的字典作为第二个参数与 URI 以逗号分隔字典中的键值对即该插件的配置选项。从命令声明上看Plugin实际委托给了 autoload/vundle.vim 中的vundle#config#bundle()而插件名会被s:check_bundle_name()见 config.vim做合法性校验合法字符集为A-Za-z0-9_-及点号并检测重名冲突。3.2 支持的 URI 格式Vundle 深度集成 GitHub 与 vim-scripts.org支持短 URI也支持任何 Git 认可的 URI。除本地路径外默认使用https协议可用g:vundle_default_git_proto覆盖。GitHub传入user/repo形式Plugin VundleVim/Vundle.vim https://github.com/VundleVim/Vundle.vimVim Scripts不含/的单词自动映射到 vim-scripts 仓库Plugin ctrlp.vim https://github.com/vim-scripts/ctrlp.vim其他 Git URI原样透传不做改写Plugin git://git.wincent.com/command-t.git本地插件file://协议适合本地开发调试Plugin file:///path/from/root/to/plugin这些规则的解析逻辑可以在 config.vim 的s:parse_name()中找到user/repo形式拼接https://github.com/...并自动补.git以git、git://、file://、http(s)://开头或带.git后缀的 URI 原样保留其余单词语默认映射到https://github.com/vim-scripts/name.git。另外源码还支持gh:与github:前缀形式见测试配置 test/vimrc 中Bundle gh:gmarik/snipmate.vim.git的用法。3.3 每插件配置选项Vundle 支持三个每插件配置选项完整定义见 doc/vundle.txtrtp选项——指定仓库内 Vim 插件所在的子目录相对仓库根目录决定加入 runtimepath 的具体路径。适用于插件位于仓库子目录的 Git 仓库Plugin git_URI, {rtp: some/subdir/}对应实现是 config.vim 的s:rtpath()若提供了rtp则返回bundle.path()/rtp的展开路径。name选项——指定本地克隆目录的名字可防止两个插件被克隆进同一目录造成命名冲突也提供额外自定义空间Plugin git_URI, {name: newPluginName}测试配置 test/vimrc 中的Bundle matchit.zip, {name: matchit}就是实际用例。pinned选项——置为 1 时Vundle 对该插件不执行任何 Git 操作但仍把已存在于 bundle 目录中的插件加入 runtimepathPlugin mylocalplugin, {pinned: 1}这允许你接入用非 Git 版本控制系统维护的插件克隆与更新由你自己负责也可以让插件停留在某个 Vundle 之前更新过的版本。注意 URI 仍会按普通插件处理只有其最后一段会加入 runtimepath官方建议该选项只配合单词形式的 URI 使用以免混淆。实现上s:sync()在 installer.vim 开头检查is_pinned()config.vim并直接返回pinned状态。4. 六大核心命令安装、更新、搜索、列表、清理4.1 安装:PluginInstall:PluginInstall安装.vimrc中配置的全部插件新装插件自动启用。它还支持按名字安装:PluginInstall unite.vim以及一次安装多个插件空格分隔:PluginInstall tpope/vim-surround tpope/vim-fugitive可用 Tab 自动补全已知脚本名。需要注意这种按名安装不是永久性的——要让插件每次启动都被加载仍需在.vimrc合适位置加入Plugin unite.vim。安装完成后若出现错误按l小写 L查看命令日志。从源码看:PluginInstall绑定到vundle#installer#new()vundle.vim无参数时操作g:vundle#bundles中全部插件带 bang 时按名字过滤更新不带 bang 且带参数时按名字逐个安装installer.vim。4.2 更新:PluginUpdate与:PluginInstall!:PluginInstall! NOTE: bang(!)或:PluginUpdate两者都会安装或更新已配置插件。更新完成后按u查看所有更新插件的变更日志按l查看命令日志。只更新指定插件:PluginInstall! vim-surround vim-fugitive或:PluginUpdate vim-surround vim-fugitive底层同步逻辑在 installer.vims:make_sync_command()根据仓库状态决定执行git clone --depth 1 --recursive --shallow-submodules首次安装或git pull git submodule update --init --recursive更新如果检测到目录存在但 origin 远程地址与配置 URI 不一致还会自动git remote set-url origin并git fetch git reset --hard origin/HEAD来完成换源对应 changelog 的 #440 Detect changed remotes update repos。更新前后通过git rev-parse HEAD对比 SHA从而判定状态是new/updated/todate并记录到g:vundle#updated_bundles供生成 changelog。4.3 搜索:PluginSearch:PluginSearch foo搜索依赖系统存在curl会向 vim-scripts.org 查询匹配的插件结果在新分割窗口中展示例如Search results for: foo Plugin MarkdownFootnotes Plugin VimFootnotes Plugin foo.vim带 bang 的:PluginSearch! foo会先刷新本地脚本缓存再搜索不加参数直接:PluginSearch!会展示已知的全部插件。实现上vundle#scripts#all()scripts.vim加载脚本数据库后用正则过滤匹配并在新窗口中渲染为可交互的Plugin ...行。4.4 列表:PluginList:PluginList列出所有已安装的插件实际展示的是已配置插件清单见 installer.vim 中的vundle#installer#list()。4.5 清理:PluginClean:PluginClean请求确认后删除所有不再在.vimrc中配置、但仍存在于 bundle 安装目录默认~/.vim/bundle/中的插件目录:PluginClean!带 bang 则自动确认删除。清理逻辑在 installer.vim它列出 bundle 目录下所有目录与当前配置插件的path()对比筛出多出来的目录带 bang 时直接执行删除否则询问Continue? [Y/n]:。删除通过rm -rfWindows 下为rmdir /S /Q见 installer.vim完成。5. 交互模式与按键映射交互模式服务于探索新插件在PluginSearch、PluginList等产生插件列表的命令之后即可使用。例如:PluginSearch! unite会生成一个带如下头部提示的分割窗口Keymap: i - Install bundle; c - Cleanup; s - Search; R - Reload list Search results for: unite Plugin unite-scriptenames Plugin unite.vim Plugin unite-yarm Plugin unite-gem Plugin unite-locate Plugin unite-font Plugin unite-colorscheme安装某个插件时把光标移到对应Plugin行上再执行命令例如安装 unite.vim将光标置于该行并按下i安装完成后:Unite file命令即可用。完整按键映射表如下映射定义见 scripts.vim按键说明i对光标所在行的插件运行:PluginInstallI同i但运行:PluginInstall!以更新该插件D删除选中的插件注意不要误删本地修改c运行:PluginCleans运行:PluginSearchR从服务器重新获取最新脚本列表u查看更新日志VundleChangelogl查看安装/更新命令日志VundleLogq关闭当前结果窗口h/?打开:h vundle需要特别提醒交互式安装不会自动修改你的.vimrc若要持久化仍需手动加入对应Plugin行。此外安装器窗口会借助 Vim 的 sign 机制展示处理状态vundle.vim 中定义了Vu_error/Vu_active/Vu_new/Vu_updated/Vu_deleted/Vu_helptags/Vu_pinned等 sign分别对应错误、处理中、新装、已更新、已删除、帮助标签重建与固定插件。6. 全局选项Vundle 提供一个全局选项g:vundle_default_git_proto用于改变构造绝对 URI 时使用的协议默认是httpslet g:vundle_default_git_proto git设置后URI 的构造方式会变为 SSH 形式例如Plugin sjl/gundo.vim - gitgithub.com:sjl/gundo.git对应解析逻辑见 config.vimgit_proto读取该全局变量git_host在git协议下使用github.com:、否则使用://github.com/。测试配置 test/vimrc 中也有对应的注释示例。7. 命令接口变迁从 Bundle 到 PluginVundle 正在经历接口变更主推Plugin命名空间同时为方便起见将部分命令别名到Vundle命名空间。变更对照如下完整定义见 doc/vundle.txt 与 autoload/vundle.vim旧名称Deprecated新名称BundlePluginBundleInstall(!)PluginInstall(!)、VundleInstall(!)BundleUpdatePluginUpdate、VundleUpdateBundleSearch(!)PluginSearch(!)、VundleSearch(!)BundleCleanPluginClean(!)、VundleClean(!)BundleListPluginListBundle系列命令仍可继续使用但已被标记为废弃且不会获得全部新功能——例如Plugin行支持行内注释而Bundle由于命令声明方式的限制不支持。完整命令清单与别名定义可见 autoload/vundle.vim其中包括额外的:PluginDocs/:VundleDocs/:BundleDocs帮助标签重建命令以及VundleUpdate/BundleUpdate对PluginInstall!的别名。8. 进阶参考完整手册Vim 内执行:h vundle或阅读 doc/vundle.txt其中包含关于 About、Quick Start、Plugins配置/URI/安装/更新/搜索/列表/清理、交互模式、按键映射、选项与接口变更的完整章节变更记录见 changelog.md当前仓库版本为 0.10.2主要更新包括将用户脚本目录置于系统目录之前rtp 顺序issue #430与重命名以g: 小写字母开头的函数以兼容 Vim patch 7.4.264issue #455测试配置test/minirc.vim 为最小可用配置test/vimrc 覆盖了各类 URI 格式、rtp/name/pinned选项与Bundle旧接口的组合并演示了vundle#rc()指定自定义 bundle 目录的用法开发背景Vundle 最初在 Vim 7.3 的 OS X、Linux 与 Windows 上开发测试设计上尽可能遵循 KISS 原则。仓库还提供了 README_ZH_CN.md、README_ZH_TW.md 与 README_KR.md 等多语言说明。从架构上看Vundle 的代码分层清晰命令入口层autoload/vundle.vim负责定义命令与别名配置层autoload/vundle/config.vim负责解析插件声明并维护 runtimepath安装执行层autoload/vundle/installer.vim负责 Git 同步、清理与帮助标签生成脚本数据层autoload/vundle/scripts.vim负责搜索、补全与日志展示。理解这四层之后无论是排查安装失败、自定义扩展行为还是迁移到其他插件管理器你都能从源码层面快速定位问题的根源。赞分享开发工具包管理器【免费下载链接】Vundle.vimVundle, the plug-in manager for Vim项目地址https://gitcode.com/gh_mirrors/vu/Vundle.vim点击查看免费下载相关推荐Vundle.vim 完全指南在 .vimrc 中管理 Vim 插件的经典方案Vundle.vim 完全指南在 .vimrc 中管理 Vim 插件的经典方案 Vundle 是 Vim bundle 的简称是一个以 .vimrc 为开发工具包管理器Bilibili-Cleaner打造专属纯净B站观影体验的终极指南Bilibili Cleaner打造专属纯净B站观影体验的终极指南 你是否厌倦了B站首页的广告轰炸是否被无关推荐视频淹没找不到真正想看的内容Bilibi前端Vim插件管理器终极指南Vundle.vim在Windows系统上的完整安装教程Vim插件管理器终极指南Vundle.vim在Windows系统上的完整安装教程 Vundle.vim是一款简单高效的Vim插件管理器它能够帮助Vim用户轻开发工具包管理器创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考