Managing Vim plugins
Plug and Play
The Vim text editor [1] is one of the most popular pieces of free software ever written. Since its first release in 1991, Vim has become available for all major operating systems. It is installed by default on most Linux distributions, and, in the 2016 LinuxQuestions Reader Choice Awards, outpolled its long-time rival Emacs by more than three to one – being the first choice of more than 30 percent of responders [2]. Much of this popularity is due to the degree of customization created by its plugins – almost 1,600, according to the VimAwesome site [3], and even that number may be low.
Most users, of course, use fewer than a dozen Vim plugins. However, even that number can be difficult to delete, although that is probably unnecessary with a recent version of Vim. The truth is, Vim's original design was not intended for plugins. Probably no one is using the oldest plugins, which needed to be unarchived in a user's home directory and were only recognized when the command :helptags
was run from within Vim. Yet even the default method of installation – dumping all plugins in ~/.vim/plugin
– can make knowing what to update or delete difficult, even with just a few plugins.
To make installing easier, four plugin managers have been developed: vim-addon-manager, Pathogen, and its enhancements Vundle and Neobundle. Which of these tools you should use depends on the services you prefer, but all take much of the pain out of managing plugins
Vim-addon-manager
Vim-addon-manager [4] is a Linux tool available in many distributions, including Debian, Ubuntu, and Fedora. Unlike the other solutions, vim-addon-manager is installed outside of Vim as a regular package. Typically, it is installed with another package that contains two dozen of the most popular plugins. The command has a registry of plugins in /usr/share/vim
, a source directory at /usr/share/vim/addons
, and a installation target at $HOME/.vim
for private use or /var/lib/vim/addons
for all system users. These directories can be changed using the options -r
, -s
, or -t
, respectively.
To view available plugins, enter vim-addons list
. Each plugin has a status of installed, removed, disabled, broken, or unavailable, which can be checked with the command vim-addons status
. Plugins are added to vim-addons with the command vim-addons install [PLUGIN]
(Figure 1).
Pathogen
Unlike vim-addons, Pathogen [5] is itself a Vim plugin, working from within Vim to manage other plugins. It is best run with GitHub as a source, because many plugins are hosted there. Pathogen's innovation is that it places all the files for each plugin within a separate directory, making them easy to find for maintenance. However, unlike Vundle and Neobundle, it does not upgrade or delete files automatically.
Because Pathogen uses a different structure from Vim's default, to avoid any problems, before installation, you should rename the existing .vim
directory (or, in Windows, ~\vimfiles
) and .vimrc
configuration file in your home folder and replace them with new ones.
To install Pathogen, log in to GitHub and run the command:
mkdir -p ~/.vim/autoload ~/.vim/bundle && curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim
These commands create the necessary directories for Pathogen and install the plugin.
Next, create a new .vimrc
file and add to it:
execute pathogen#infect() syntax on filetype plugin indent on
These lines start Pathogen before any other plugin so that it can manage them. Optionally, you can add:
call pathogen#runtime_append_all_bundles() call pathogen#helptags() "
to update the help automatically each time Vim starts. To add other plugins from GitHub, change directories to ~/.vim/bundle
and run:
git clone git://github.com/[WRITER]/[PLUGIN PATH] ~/.vim/bundle/[PLUGIN PATH]
Should you be using another source for plugins, adjust the command accordingly. You can use the old files as a list of plugins to reinstall under Pathogen's management before deleting them.
Vundle
Vundle [6] (short for "Vim bundles," the name it uses for plugins) is an enhancement of Pathogen. Like Pathogen, Vundle rearranges the directory structure to make management easier. However, Vundle updates plugins automatically and adds several utilities as well.
Windows users have a graphical interface for installing and a choice of whether to run Vundle in a Bash shell – if one is installed – or from a Windows command prompt. Probably, they will need to install curl as well.
On Linux, however, installation is only a matter of running:
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
Notice that, unlike Pathogen, Vundle is installed to a sub-directory of .vim/bundle
, just like any other plugin.
To update plugins automatically with Vundle, add to .vimrc
the following lines (see also Figure 2):
set nocompatible filetype off set rtp+=~/.vim/bundle/Vundle.vim call vundle#begin() Plugin 'VundleVim/Vundle.vim'
These lines set the run-time path to Vundle, initiate it, and set Vundle to manage itself. Below the last line, add the other plugins that Vundle manages, one per line, starting with Bundle, for example:
Bundle 'tpope/vim-fugitive'
The GitHub Vundle page gives examples of how to list other sources that you might use.
Installing Vundle also installs four utilities that are run from within Vim. Their names are self-explanatory. Bundlelist lists configured plugins, BundleInstall installs or updates a plugin, BundleSearch searches for a plugin, and BundleClean removes plugins with a confirmation message. The BundleInstall, BundleSearch, and BundleClean commands are completed by the name of a plugin.
Note that future versions of Vundle will replace the use of "Bundle" with "Plugin." BundleInstall, for instance, will be renamed PluginInstall.
Buy this article as PDF
(incl. VAT)