Open Source Subnet An independent Open Source community View more

Three tools for managing Vim plugins

The venerable Vim editor lets you add plugins to enhance features and functionality. The more plugins you add, the greater the challenge you may have managing them, since the standard instructions for installing plugins are not always consistent. Older plugins are downloaded in archived format; you need to extract them to the .vim subdirectory in your home directory and run the command :helptags the next time you start Vim. More recent plugins only need to be moved to ~/.vim/plugin to be available the next time that you start Vim. The second installation method is more orderly than the first, but you need to check which to use each time that you add a plugin. And with either method, you have to update each plugin (or delete it) manually.

If managing Vim plugins gets you in a muddle, you can turn to three tools that can make managing other plugins easier: vim-addons, Pathogen, and Vundle.

vim-addon-manager

vim-addons is a command-line plugin manager that you run outside of Vim. On Debian, Fedora, and Ubuntu and their derivative distributions, you can add it by installing the package vim-addon-manager. On distributions where it is available, you might also want to add vim-scripts, which downloads two dozen popular Vim plugins, thereby letting you manage Vim with the package manager as much as possible.

The vim-addon-manager command follows the basic command with both subcommands and options; for example, vim-addons -v install vim-fugitive installs Vim-fugitive with a verbose description of what is happening. The command uses a registry directory (/usr/share/vim/registry), a source directory for addons (user/share/vim/addons), and a target directory for installation ($HOME/.vim for an ordinary user, /var/lib/vim/addons for all users when you are logged in as root). You can change the default for all these directories by using an option to specify an alternative directory.

To begin using vim-addons, enter vim-addons |less to see a list of all plugins on the system and their status. To install plugins, enter vim-addons install <em>[PLUGIN]</em>. To remove a plugin, use remove as the subcommand. You can use the subcommand disable to make a plugin unavailable from an account, or enable to restore its use.

Pathogen

Rather than a separate utility like vim-addons, our second utility, Pathogen, is a Vim plugin for managing other plugins. Pathogen works with a subdirectory structure that places all the files for each plugin together, unlike the directory structure used by standard Vim. The advantage is that while you must still perform deletions and upgrades manually, Pathogen leaves you in no doubt of what directories and files are involved.

This difference in directory structure raises the possibilty of conflicts. For this reason, before you install Pathogen, remove or rename any .vim directory or .vimrc configuration file in your home folder and replace them with new, empty ones. The new .vim directory must contain the subdirectories autoload and bundle before you install Pathogen.

You can find Pathogen on GitHub.com, which hosts the most complete set of Vim plugins. When the new .vim directory is ready, create a GitHub account and log in to download Pathogen from GitHub to ~/.vim/autoload with one of the following commands. If you use Git, run:

git clone git://github.com/tpope/vim-pathogen/raw/master/autoload/pathogen.vim ~/.vim/autoload/pathogen.vim

If you prefer cURL, run:

curl -k https://github.com/tpope/vim-pathogen/raw/master/autoload/pathogen.vim > ~/.vim/autoload/pathogen.vim

Once you've copied the directory structure to your .vim directory, create a .vimrc file and add the lines:

filetype off
call pathogen#runtime_append_all_bundles()
call pathogen#helptags() "
filetype plugin indent ongit clone git://github.com/tpope/vim-fugitive

These lines ensure that Pathogen is not treated as just another plugin as it loads, and that it starts before any other ones so it can take over plugin management. In addition, they automatically update the help for all plugins managed by Pathogen each time that Vim starts, so you no longer have to worry about manually regenerating it each time that you add a new plugin.

Once Pathogen is installed, adding another plugin is a matter of adding its directory structure. Change to ~/.vim/bundle and download your new plugin from GitHub using the command structure:

git clone git://github.com/<em>[MAINTAINER]</em>/ <em>[PLUGIN PATH]</em> ~/.vim/bundle/<em>[PLUGIN PATH]</em>

or, if you prefer cURL:

curl -k https://github.com/<em>[MAINTAINER]</em>/ <em>[PLUGIN PATH]</em> > ~/.vim/bundle/<em>[PLUGIN PATH]</em>

The next time you start Vim the plugin should be loaded and running. Once you have Pathogen you have no further need for your old .vim and .vimrc files, except as a list of plugins you still need to transfer to Pathogen's management.

If you find a plugin that is incompatible with Pathogen – which is unlikely these days – you're better off trying to find another plugin with similar features than falling back on Vim's standard plugin management. Pathogen's rationalization of plugin management is too useful to discard unless you have no other choice.

Vundle

Our third utility, Vundle, refers to plugins as bundles, and is short itself for "Vim bundle." All plugins that work with Pathogen also work with Vundle, and Vundle has all the advantages of Pathogen – but in addition, Vundle provides automatic updates of plugins, as well as utilities that provide features similar to those available through vim-addons.

Vundle is located at /gmarik/vundle on Github. Unlike Pathogen, Vundle should be placed in ~/.vim/bundle, the same as any other plugin that it is to manage. To work, it requires the same directory structure as Pathogen, plus the following lines in .vimrc:

set nocompatible             
filetype off
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
Bundle 'gmarik/vundle'
filetype plugin indent on  

You can add other plugins, one per line, below the line for Vundle (for example, Bundle 'tpope/vim-fugitive'). Each plugin listed will be updated automatically each time you start Vim.

NeobundleNeobundle has emerged. Neobundle is essentially a rewrite of Vundle with a change of names, with Vundle's :BundleClean utility, for example, being replaced by Neobundle's :NeoBundleClean. But it includes additional features that go far beyond plugin management. Idiosyncratic, diverse, and apparently under rapid development, Neobundle is currently not an alternative I would recommend, especially to those dependent on the English translations of its Japanese documentation.

In the last couple of years, a fourth plugin manager called

Installing Vundle also enables four utilities that you can use from within Vim:

  • :BundleList: Lists configured plugins
  • :BundleInstall <em>[PLUGIN]</em>: Installs or updates plugins
  • :BundleSearch <em>[PLUGIN]</em>: Searches for a plugin
  • :BundleClean <em>[PLUGIN]</em><code>: Removes plugins with manual confirmation or auto-approve. </code>

Run :BundleInstall without specifying any plugins the first time you open Vim with Vundle, and every time after you add a plugin.

Which to choose?

So which of the three alternatives should you use?

vim-addons-manager has the advantage of using package management, which means that all – or at least most – of the additions to your system are under one system, especially if you content yourself with the plugins available in vim-scripts. If you are familiar with Debian- or Ubuntu-specific tools such as apt-get, this utility's command structure should be immediately familiar. In addition, vim-addons is better suited than Pathogen or Vundle for installing plugins for all users rather than for individual accounts.

As for Pathogen or Vundle, at first you might choose Vundle because of its larger feature set. However, if you are security-conscious, you might have second thoughts about whether you want automatic updates. The problem is not so much that the updates make Vim start more slowly – you would need dozens of plugins for that to be a problem – so much as you prefer to know when the system changes.

You might also decide that having to edit .vimrc each time you add a plugin to Vundle cancels out at least some of the advantage of automatic updates. Checking the directory structure of ~/.vim/bundle from the command line while running Pathogen is really no more difficult than running Vundle's utilities within Vim. In fact, you might find running Pathogen easier because you are already familiar with basic commands like ls and rm, and don't need to learn new ones.

In other words, the choice depends on what you are used to and how you prefer to work. Any of the three is more efficient than relying on unmodified Vim's options, and you can easily switch to another if one fails to suit you.

To comment on this article and other Network World content, visit our Facebook page or our Twitter stream.
Must read: Hidden Cause of Slow Internet and how to fix it
Notice to our Readers
We're now using social media to take your comments and feedback. Learn more about this here.