Installing Vim(8) plugins with the native pack system

Paulo Diovani
3 min readNov 5, 2019

--

Vim (vim.org) is a powerful terminal text editor very popular among Linux and Mac users, especially among developers, due to its potential to increase productivity. It is actually so popular that it has also a GUI version, called Gvim, and vim-mode plugins for most of the other text editors out there, including Sublime, Atom and VS Code.

Vim always had tons of plugins available, for simple things like color schemes or a better status line (powerline, airline, lightline) to more complex like a tree file browser (nerdtree), fuzzy directory search (ctrlp) or git integration (fugitive), just to mention some. It wasn’t, on the other hand, much user-friendly to install plugins, that is why there were also plugins for installing plugins (pathogen, vundle, plug).

These plugins usually define a new directory for installed plugins (default was ~/.vim/plugin) and some scripts to fetch the plugin code from GitHub and place in this directory, mimicking the behavior of other editors package managers.

Until now…

Vim 8 packages

Version 8 introduced a new, very simple, pack system for installing plugins, created to help users manage all of their plugins in the same archive. Instead of creating a new way for downloading plugins as the afore-mentioned solutions do, it just defines a new plugin directory structure, and the user can decide how to fetch and update plugins.

From vim :help packages

A Vim package is a directory that contains one or more plugins. The
advantages over normal plugins:
- A package can be downloaded as an archive and unpacked in its own directory.
Thus the files are not mixed with files of other plugins. That makes it
easy to update and remove.
- A package can be a git, mercurial, etc. repository. That makes it really
easy to update.
- A package can contain multiple plugins that depend on each other.
- A package can contain plugins that are automatically loaded on startup and
ones that are only loaded when needed with `:packadd`.

Any directory under ~/.vim/pack is considered a package. A package can hold plugins in two different directories, start and opt. The plugins under start/ folder are loaded on startup, while the plugins under opt/ folder are loaded manually by the user with the command :packadd.

  • ~/.vim/pack/*/start/{name}
    Plugin auto loaded on startup
  • ~/.vim/pack/*/opt/{name}
    Plugin loaded manually, with :packadd {name}

When using Vim packages, you can unpack or git clone your desired packages directly into these directories. Or even use git submodules to keep them all in sync among several machines.

Installing and organizing Vim packages

The final directory structure under ~/.vim/pack is up to your own organization, but here goes what I do…

I split my plugins into three different packages:

  • ~/.vim/pack/plugins
    For general plugins or anything that doesn't fit on the other directories.
  • ~/.vim/pack/colors
    For color schemes
  • ~/.vim/pack/syntax
    For language syntax, compilers, linters, etc.

Each of these directories can have two folders, start, and opt, with plugins on each one.

To install and keep them synced, I use git submodules (git-scm.com/book/en/v2/Git-Tools-Submodules) and keep them saved in my dot-files repository (github.com/paulodiovani/dot-files).

Here is an example of how to install packages under ~/.vim/pack using git submodules.

So, the new git package system is yet simple and even easier to maintain/update if you already use git to keep your configs synced.

My own setup is a bit more complex, since I have the submodules in an external repository (not under ~/.vim/pack) and use a Makefile to copy them to their final destination. But the result is the same. You can see the whole setup in my dot-files repository.

Conclusion: Should I drop Pathogen/Vundle/Plug and start using the native packages?

The short answer is No. These (and others) solutions for managing plugins will still work, and you should probably keep using if you’re comfortable with them.

The new Vim Packages are, however, a great option for starters, or who didn’t know the previous solutions, or even for who wants more flexibility while handling vim plugins.

Sources:
- https://vimhelp.org/repeat.txt.html#packages
- https://vi.stackexchange.com/questions/9522/what-is-the-vim8-package-feature-and-how-should-i-use-it
- https://shapeshed.com/vim-packages/

--

--

Paulo Diovani

Bookworm, RPG player, TV Shows addicted, Cat lover, Internet Systems Technologist and Software Engineer.