Managing Vim plugins
Added Features
Managing plugins is a requirement for Vim users, and plugin managers can make the task easier. We look at four options.
Vim is not a text editor so much as a way of life. Vim, which traces its lineage back to Vi, has accrued plugins during its 36-year history the way offshore rocks accrue barnacles. From file managers and spell checkers to multiple-entry clipboards and undo levels, Vim plugins ingeniously offer from the command line every utility you can imagine on the desktop – and probably some that you can't. Regular users can be known to install more than a dozen at a time, which makes managing them a basic requirement.
The trouble is, Vim was never made to handle the large number of plugins that many modern users install. Without a manager, a plugin either has to be dropped into ~/.vim/plugin
, or, in the case of very old plugins, simply ~/.vim
. However, its files are unsorted, which means you have to update or delete each plugin manually. In some cases, you also need to run the command :helptags
if you want online help.
Plugin managers are designed to spare users these trials. Vim-addons [1] treats plugins as packages, whereas Pathogen [2] – itself a plugin – creates separate directory structures for each plugin under ~/.vim
, making updating and deleting much easier. By contrast, Vundle [3] and NeoBundle [4] rely on Pathogen's structure but add automatic updates and other features. Each of these alternatives is considerably easier than adding plugins to unmodified Vim, but which to choose depends on your work habits, as well as your notions of security.
Vim-addons
Vim-addons is unique among Vim managers in that it operates entirely outside Vim, treating plugins as packages and using a command syntax very similar to Debian's apt-get
, with commands and subcommands. On distributions where it is available, such as Debian, Fedora, and Ubuntu, its own package is called vim-addon-manager. (Notice that the command itself is simply vim-addon
.) Distributions that include vim-addon-manager often include vim-scripts [5], which downloads about 25 common Vim plugins that vim-addon-manager can then install.
Vim-addons manages plugins that are stored in /usr/share/vim/addons
, where they are conveniently organized into categories by subdirectories, registering them in the directory /usr/share/vim/registry/
and installing them in ~/.vim
for an ordinary user or in /var/lib/vim/addons
for all users.
Typing vim-addons list
presents the available plugins (Figure 1). Adding the sub-command files
followed by a plugin name shows the files associated with a registered plugin, whereas show
plus a plugin gives more detailed information about a registered plugin.
To active a plugin for the current account with Vim-addon, download it and uncompress it if necessary, then enter the following command while logged in as root:
vim-addons install [PLUGIN PATHS]
Removing a plugin uses a similar structure:
vim-addons remove [PLUGIN]
From a non-root account, you can use the sub-command disable
to make a plugin unavailable to that account or use enable
to make a plugin available without affecting whether other users can use it.
The advantage of Vim-addons is that you need to know nothing about Vim to use it, and you do not even need to edit text files for configuration. You may have to look up registered plugins online to see what they do, but that is no different from any other plugin manager.
Pathogen
Pathogen was the first Vim plugin for managing other plugins. Pathogen's major innovation is a directory structure that places all the files for each plugin in its own subdirectory. With Pathogen, you still need to upgrade or delete plugins manually, but you no longer have to check which files belong with which plugin; nor do you need to worry about naming conflicts.
This directory structure is so different from Vim's default directory structure that, before you install Pathogen, you should delete any ~/.vim
directory or ~/.vimrc
file in your home folder – or, possibly, move them so that you have a list of plugins you will want to reinstall once Pathogen is configured.
Create an empty .vim
and .vimrc
and use mkdir
to create the new subdirectories ~/.vim/autoload
and ~/.vim/bundle
. The autoload
subdirectory contains plugins that you always want to load with Vim, and the bundle
subdirectory contains a separate directory for each plugin's files ("bundle" being Pathogen's alternative name for plugins).
To install Pathogen, you can create the directory ~/.vim/autoload/pathogen.vim
and drop the plugin into the new directory. If you want the latest version, make sure curl is installed and create a GitHub account for yourself. Then run the commands:
mkdir -p ~/.vim/autoload ~/.vim/bundle && curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim
Both of these installation methods position Pathogen so that it loads automatically each time you start Vim.
However, to finish installing Pathogen, you also need to add the lines in Listing 1 to a clean ~/.vimrc
. These lines are the bare minimum you need to use Pathogen. They prevent Vim from treating Pathogen as simply another plugin and load Pathogen before any other plugins so that it can manage the rest.
Listing 1
.vimrc for Pathogen
execute pathogen#infect() syntax on filetype plugin indent on
If you choose, you can also add the line call pathogen#helptags()
so that Vim automatically generates new online help files each time it starts, freeing you from manually updating the help files each time you add a new plugin. However, be warned that if you have multiple plugins, Vim may take a few seconds longer to start with this option.
At this point, Pathogen is configured for use. To add a plugin, add a new directory for it under ~/.vim/bundle/
and place the plugin in the new directory. You can take advantage of GitHub to use the latest version of the plugin, using the command structure:
git clone git://github.com/[WRITER]/[PLUGIN PATH] ~/.vim/bundle/[PLUGIN PATH]
These days, you should find few plugins that are incompatible with Pathogen. However, if you do, you have a good chance of finding another plugin that does much the same thing. Pathogen is useful enough that, if you have to choose between Pathogen and another plugin, whenever possible you should keep Pathogen and discard the other plugin.
Vundle
Vundle is an enhancement of Pathogen. It uses the same directory structure as Pathogen but automatically updates plugins and includes several utilities for use within Vim. It also offers clear, concise instructions.
The quickest way to install Vundle is to clone the latest version on GitHub:
git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim
At the minimum, Vundle also requires the lines shown in Listing 2 in .vimrc
.
Listing 2
.vimrc for Vundle
set nocompatible filetype off" set rtp+=~/.vim/bundle/Vundle.vim call vundle#begin() Plugin 'gmarik/Vundle.vim' call vundle#end() filetype plugin indent on
To update plugins automatically, you can place other plugins, one per line, between the call vundle#begin()
and call vundle#end()
lines and below the Plugin 'gmarik/Vundle.vim'
line. Vundle assumes that you are downloading from GitHub, so only the repository's owner and the plugin's file name are needed to enable automatic updates. If you are using another repository, the full path is needed, as illustrated in the sample .vimrc
on Vundle's homepage [3].
When using Vim, install other plugins just as you installed Vundle, creating a Vim clone in a subdirectory of ~/.vim/bundle/
. Plugins are enabled by running vim +PluginInstall +qall
from the command line or :PluginInstall
from inside Vim. Both commands enable all plugins added since the last time one of them was run.
Also included in Vundle are three other utilities that work from within Vim:
:BundleList
: Lists all plugins being managed by Vundle.:BundleClean
: Removes unused plugins. The basic command asks for confirmation of each deletion, whereas:BundleClean(!)
removes plugins without any input.:PluginSearch [STRING]
: Locates all plugins whose file names contain the entered string and opens a list in a new window from which you can install or remove them. If you install, you still need to add a line to.vimrc
to enable the plugin.:PluginSearch
requires curl to work (Figure 2).
As you can see, Vundle adds a new level of functionality to Pathogen, making plugin management even simpler.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
New Steam Client Ups the Ante for Linux
The latest release from Steam has some pretty cool tricks up its sleeve.
-
Gnome OS Transitioning Toward a General-Purpose Distro
If you're looking for the perfectly vanilla take on the Gnome desktop, Gnome OS might be for you.
-
Fedora 41 Released with New Features
If you're a Fedora fan or just looking for a Linux distribution to help you migrate from Windows, Fedora 41 might be just the ticket.
-
AlmaLinux OS Kitten 10 Gives Power Users a Sneak Preview
If you're looking to kick the tires of AlmaLinux's upstream version, the developers have a purrfect solution.
-
Gnome 47.1 Released with a Few Fixes
The latest release of the Gnome desktop is all about fixing a few nagging issues and not about bringing new features into the mix.
-
System76 Unveils an Ampere-Powered Thelio Desktop
If you're looking for a new desktop system for developing autonomous driving and software-defined vehicle solutions. System76 has you covered.
-
VirtualBox 7.1.4 Includes Initial Support for Linux kernel 6.12
The latest version of VirtualBox has arrived and it not only adds initial support for kernel 6.12 but another feature that will make using the virtual machine tool much easier.
-
New Slimbook EVO with Raw AMD Ryzen Power
If you're looking for serious power in a 14" ultrabook that is powered by Linux, Slimbook has just the thing for you.
-
The Gnome Foundation Struggling to Stay Afloat
The foundation behind the Gnome desktop environment is having to go through some serious belt-tightening due to continued financial problems.
-
Thousands of Linux Servers Infected with Stealth Malware Since 2021
Perfctl is capable of remaining undetected, which makes it dangerous and hard to mitigate.