Working With Vim Plugins

Plugins are 80% of what makes Vim awesome. You take this great foundation, and then you pile on 25 years worth of developers going “ooh, I bet I can make it do this nifty thing.” The result is amazing, and as far as I can tell, all those ancient plugins still work.

Everything isn’t perfect in the land of plugins. For a while it was download, and expand a zip file, or load a vimball (don’t ask). Recently there has been a proliferation of plugin managers (thank [insert deity here]), and now in Vim 8, Vim even has its own plugin manager built in. Yay.

So, you’ve got choices. This is my site, so I’m going to give you my opinionated advice. Use vim-plug. I’d love to recommend the built-in one, but as far as I can tell vim-plug still kicks its butt.

Advantages of vim-plug:

  • Parallelized installation of plugins
  • You can limit a plugin to specific file types, so that you don’t waste resources loading and running a plugin for Ruby when you’re editing a Python file.
  • Fast
  • Easy
  • Works
  • Works with older versions of Vim.
  • Supports different sets of plugins for different .vimrc files.

Once you’ve pasted in the initial configuration adding a plugin is usually as simple as saying

Plug 'bling/vim-airline'

then reloading your changes and running :PlugInstall

bling/vim-airline comes from the GitHub url of the vim-airline plugin: https://GitHub.com/bling/vim-airline

Pathogen was the 1st good plugin manager for Vim. You’ll come across a lot of plugins that haven’t been updated in a while that only mention Pathogen. Don’t worry about it. If you can install it with Pathogen you can install it with the other plugin managers using their standard syntax.

Plugins Not On GitHub

The migration of vim plugins to GitHub has been impressive, and largely fueled by the fact that the best plugin managers all make it very easy to install from GitHub. Vim has been around for 25 years though, and a there are a lot of really useful things that haven’t made it to GitHub. There are also a bunch of developers who don’t like using GitHub. If the plugin you want isn’t on GitHub your plugin manager will still have a relatively easy way to install and manage it.

Restart after install

In my experience your best plan, regardless of which plugin manager you choose, is to:

  1. add the plugin to your .vimrc
  2. source it ( See the section on reloading your .vimrc )
  3. tell your plugin manager to download and install it.
  4. then restart vim.

Writing Plugins

Plugin creation is one area where the modern JavaScript powered editors kick Vim’s butt. Fortunately, it’s unlikely you’ll need to write any for a long time, because there are tons of awesome ones out there that enable Vim to do just about every nifty thing you could want.

That being said, Vim supports plugins written in its native Vimscript, Python, Ruby, Perl, Scheme, and Tcl. Steven Bach1 has this to say about writing plugins in languages other than Vimscript:

It isn’t widely known that Vim has interfaces into several popular scripting languages: Python, Ruby, Perl, Scheme, and Tcl. These are more powerful than Vim Script but have certain practicality drawbacks in context.

  1. Debugging is difficult. Foreign code is interpreted by what is essentially one giant eval. If you misplace a close parenthesis or an end keyword, you will have to track it down yourself.

  2. Integration with Vim is slight.[…] The bindings just tunnel most editor interactions through Vim::evaluate or Vim::command (or equivalent) as unstructured string arguments.

  3. Many Vim installations don’t include external language support by default. It’s an easy fix for a user running a deb or rpm-based Linux distribution, but will require a recompile on Windows, something a Windows user is not wont to do. OS X is hit-or-miss.

Steven’s article is filled with technical tips, and I highly recommend check out Steve Losh’s post with great advice for plugin creators. He’s also the author of Learn Vimscript The Hard Way. It’s free to read online, but if you find it useful please buy a copy of the eBook or print versions.