如何在Linux上使用Vundle管理Vim插件

系统 Linux
Vim 是一款强大的文本文件处理的通用工具,能够管理系统配置文件和编写代码。Vundle 为每一个你安装的插件创建一个独立的目录树,并在相应的插件目录中存储附加的配置文件。在这个简易的教程中,让我告诉你如何安装 Vundle,如何在 GNU/Linux 中使用它来管理 Vim 插件。

https://s3.51cto.com/oss/201803/07/9c6913e9e7d716bdcec12a2e595d822c.png

毋庸置疑,Vim 是一款强大的文本文件处理的通用工具,能够管理系统配置文件和编写代码。通过插件,Vim 可以被拓展出不同层次的功能。通常,所有的插件和附属的配置文件都会存放在 ~/.vim 目录中。由于所有的插件文件都被存储在同一个目录下,所以当你安装更多插件时,不同的插件文件之间相互混淆。因而,跟踪和管理它们将是一个恐怖的任务。然而,这正是 Vundle 所能处理的。Vundle,分别是 Vim 和 Bundle 的缩写,它是一款能够管理 Vim 插件的极其实用的工具。

Vundle 为每一个你安装的插件创建一个独立的目录树,并在相应的插件目录中存储附加的配置文件。因此,相互之间没有混淆的文件。简言之,Vundle 允许你安装新的插件、配置已有的插件、更新插件配置、搜索安装的插件和清理不使用的插件。所有的操作都可以在一键交互模式下完成。在这个简易的教程中,让我告诉你如何安装 Vundle,如何在 GNU/Linux 中使用它来管理 Vim 插件。

 

Vundle 安装

如果你需要 Vundle,那我就当作你的系统中,已将安装好了 Vim。如果没有,请安装 Vim 和 git(以下载 Vundle)。在大部分 GNU/Linux 发行版中的官方仓库中都可以获取到这两个包。比如,在 Debian 系列系统中,你可以使用下面的命令安装这两个包。

  1. sudo apt-get install vim git

 

下载 Vundle

复制 Vundle 的 GitHub 仓库地址:

  1. git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

 

配置 Vundle

创建 ~/.vimrc 文件,以通知 Vim 使用新的插件管理器。安装、更新、配置和移除插件需要这个文件。

  1. vim ~/.vimrc

在此文件顶部,加入如下若干行内容:

  1. set nocompatible " be iMproved, required
  2. filetype off " required
  3.  
  4. " set the runtime path to include Vundle and initialize
  5. set rtp+=~/.vim/bundle/Vundle.vim
  6. call vundle#begin()
  7. " alternatively, pass a path where Vundle should install plugins
  8. "call vundle#begin('~/some/path/here')
  9.  
  10. " let Vundle manage Vundle, required
  11. Plugin 'VundleVim/Vundle.vim'
  12.  
  13. " The following are examples of different formats supported.
  14. " Keep Plugin commands between vundle#begin/end.
  15. " plugin on GitHub repo
  16. Plugin 'tpope/vim-fugitive'
  17. " plugin from http://vim-scripts.org/vim/scripts.html
  18. " Plugin 'L9'
  19. " Git plugin not hosted on GitHub
  20. Plugin 'git://git.wincent.com/command-t.git'
  21. " git repos on your local machine (i.e. when working on your own plugin)
  22. Plugin 'file:///home/gmarik/path/to/plugin'
  23. " The sparkup vim script is in a subdirectory of this repo called vim.
  24. " Pass the path to set the runtimepath properly.
  25. Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
  26. " Install L9 and avoid a Naming conflict if you've already installed a
  27. " different version somewhere else.
  28. " Plugin 'ascenator/L9', {'name': 'newL9'}
  29.  
  30. " All of your Plugins must be added before the following line
  31. call vundle#end() " required
  32. filetype plugin indent on " required
  33. " To ignore plugin indent changes, instead use:
  34. "filetype plugin on
  35. "
  36. " Brief help
  37. " :PluginList - lists configured plugins
  38. " :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate
  39. " :PluginSearch foo - searches for foo; append `!` to refresh local cache
  40. " :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal
  41. "
  42. " see :h vundle for more details or wiki for FAQ
  43. " Put your non-Plugin stuff after this line

被标记为 “required” 的行是 Vundle 的所需配置。其余行仅是一些例子。如果你不想安装那些特定的插件,可以移除它们。完成后,键入 :wq 保存退出。

***,打开 Vim:

  1. vim

然后键入下列命令安装插件:

  1. :PluginInstall

将会弹出一个新的分窗口,我们加在 .vimrc 文件中的所有插件都会自动安装。

安装完毕之后,键入下列命令,可以删除高速缓存区缓存并关闭窗口:

  1. :bdelete

你也可以在终端上使用下面命令安装插件,而不用打开 Vim:

  1. vim +PluginInstall +qall

使用 fish shell 的朋友,添加下面这行到你的 .vimrc 文件中。

  1. set shell=/bin/bash

 

使用 Vundle 管理 Vim 插件

 

添加新的插件

首先,使用下面的命令搜索可以使用的插件:

  1. :PluginSearch

要从 vimscripts 网站刷新本地的列表,请在命令之后添加 !

  1. :PluginSearch!

会弹出一个列出可用插件列表的新分窗口:

你还可以通过直接指定插件名的方式,缩小搜索范围。

  1. :PluginSearch vim

这样将会列出包含关键词 “vim” 的插件。

当然你也可以指定确切的插件名,比如:

  1. :PluginSearch vim-dasm

移动焦点到正确的一行上,按下 i 键来安装插件。现在,被选择的插件将会被安装。

类似的,在你的系统中安装所有想要的插件。一旦安装成功,使用下列命令删除 Vundle 缓存:

  1. :bdelete

现在,插件已经安装完成。为了让插件正确的自动加载,我们需要在 .vimrc 文件中添加安装好的插件名。

这样做:

  1. :e ~/.vimrc

添加这一行:

  1. [...]
  2. Plugin 'vim-dasm'
  3. [...]

用自己的插件名替换 vim-dasm。然后,敲击 ESC,键入 :wq 保存退出。

请注意,所有插件都必须在 .vimrc 文件中追加如下内容。

  1. [...]
  2. filetype plugin indent on

 

列出已安装的插件

键入下面命令列出所有已安装的插件:

  1. :PluginList

 

更新插件

键入下列命令更新插件:

  1. :PluginUpdate

键入下列命令重新安装所有插件:

  1. :PluginInstall!

 

卸载插件

首先,列出所有已安装的插件:

  1. :PluginList

之后将焦点置于正确的一行上,按下 SHITF+d 组合键。

然后编辑你的 .vimrc 文件:

  1. :e ~/.vimrc

删除插件入口。***,键入 :wq 保存退出。

或者,你可以通过移除插件所在 .vimrc 文件行,并且执行下列命令,卸载插件:

  1. :PluginClean

这个命令将会移除所有不在你的 .vimrc 文件中但是存在于 bundle 目录中的插件。

你应该已经掌握了 Vundle 管理插件的基本方法了。在 Vim 中使用下列命令,查询帮助文档,获取更多细节。

  1. :h vundle

现在我已经把所有内容都告诉你了。很快,我就会出下一篇教程。保持关注!

干杯!

 

资源

Vundle GitHub 仓库 

责任编辑:庞桂玉 来源: Linux中国
相关推荐

2015-07-15 09:18:12

LinuxVimVundle

2022-06-20 08:08:04

Vim

2018-12-11 11:00:50

Linux字体命令

2019-01-07 09:50:06

Linuxtarball命令

2019-11-26 16:58:51

Linuxpkgsrc

2023-01-17 07:40:59

LinuxAppImage应用程序

2021-10-02 10:10:47

LinuxBusyBox命令

2020-08-24 12:37:54

Linuxxargs命令

2014-07-14 09:24:51

Debiansystemd

2022-04-15 19:19:28

Vim编辑器

2022-08-10 13:12:04

Linuxcat命令

2022-05-16 09:11:56

LinuxVimVim-plug

2014-06-09 10:23:20

2018-04-25 09:33:54

Windows 10Vim Text Ed

2014-05-07 09:56:48

Docker管理Linux容器

2021-08-03 14:33:53

cron定时器Linux命令

2015-08-21 09:07:52

LinuxNMAP安全

2018-08-06 09:30:00

LinuxPbcopyPbpaste

2018-04-25 10:46:05

Linux命令行日历

2022-09-19 08:45:52

Telnet系统Linux
点赞
收藏

51CTO技术栈公众号