Plugin installation
While we tilt towards native Vim functionality on this list, most Vim power users will extend Vim’s capabilities at some point with any of the thousands of open-source plugins available. If you don’t live and breathe Vim, you might not be aware of just how many ways their to install and manage plugins, including a built-in method that shipped with Vim 8.
If you’re still using one of the non-native package managers, you might be missing out on one of the best tricks of Vim’s native, lightweight, package manager: The ability to load optional plugins on the fly. Read on for that tip. Please excuse the diversion from the usual quick-tip format this week, but here’s an overview of 4 different Vim plugin installation methods.
Vim’s Native Package Manager
Beginning with Vim 8, Vim ships with its own package management capability. If you are on Vim 8 and are using a plugin manager like any of the ones below, there really is no need to. (If you’re not on Vim 8, why not?) To install plugins in Vim 8, they simply need to be in the right place and Vim will find them and load them. That place can be anywhere under ~/.vim/pack/*/start
so here’s how to set that up:
$ mkdir -p ~/.vim/pack/vendor/start
We’ll use the vendor
convention since these are libraries from outside vendors, but you don’t have to. You could create separate directories for colorschemes
, syntax
, etc. Any Vim plugin can then just be dropped in a directory under any one of those. Most people clone plugins via Git like so:
$ git clone https://github.com/tpope/vim-vividchalk ~/.vim/pack/vendor/start/vim-vividchalk
The advantage to using Git is, of course, ease of updating. You can git pull
inside any of these plugin directories to update them. Or, what I do, update them all at once, with regularity:
for i in ~/.vim/pack/vendor/start/*; do git -C $i pull; done
One of the most useful features of Vim’s native package manager is the ability to load some plugins optionally. Instead of a start
directory, you can use an opt
directory, and those plugins are not loaded automatically. Instead, you can load them on demand inside Vim:
:packadd plugin-name
All of the above also works in NeoVim, but it uses a different directory location: ~/.local/share/nvim/site/pack
.
Pathogen
Pathogen is the pioneer of Vim package managers, leading the way for Vim to adopt similar functionality, and for other package managers to offer slightly different methods of installation. Installing Pathogen is easy: simply copy the pathogen.vim
file into your ~./vim/autoload
directory and add the following to your .vimrc
:
execute pathogen#infect()
Now, any plugins you want to install can just be dropped into their own subdirectories under ~/.vim/bundle
and they will be loaded when Vim starts. If you clone plugins via Git, you can use the method above to update all the plugins at once.
So why would you want to use Pathogen over Vim’s native capability? Well, you might not. In fact, Tim Pope, the maintainer of Pathogen, recommends using Vim’s built-in package management instead.
Vim-Plug
Vim-Plug claims to be “a minimalist Vim plugin manager” but on the contrary, it’s packed with features and offers much more capability than either native packages or Pathogen. Most notably, the ability to update plugins from within Vim, including reviewing and rolling back updates.
You’ll want to review the README for detailed installation and usage instructions. Notably, instead of just reading a directory of directories, Vim-Plug requires specifying the plugins to be installed inside your .vimrc
. For example:
" the essential Git plugin
Plug 'tpope/vim-fugitive'
The format is the familiar GitHub owner and repo name. One advantage to this style of plugin installation is the ability to annotate your plugin usage with comments. And there are many options you can specify such as loading a specific branch, or on-demand plugin loading in certain file types, so review the examples.
Once you’ve specified your plugins, just run :PlugInstall
to install new ones. Or, update all your plugins with :PlugUpdate
.
Vundle
The most popular package manager by Github stars, Vundle is similar to Vim-Plug in that it allows you to update your plugins in Vim. You also specify the plugins to install right inside your .vimrc
, similar to Vim-Plug.
See the README for the installation, but it’s quick and easy. The format of plugin references is almost identical to Vim-Plug but uses the Plugin
keyword instead of Plug
. Like so:
" handles brackets, parens, quotes, etc.
Plugin 'tpope/vim-surround'
To install new plugins with Vundle, run :PluginInstall
or add a bang to it to update existing plugins: :PluginInstall!
.