Vim 8 package management

How it works

Vim 8 introduced native package management, providing an alternative to popular tools such as Vundle and vim-plug.

The documentation on Vim 8's package management can be accessed via :h packages. It defines a package as a directory that contains one or more plugins. The main highlights of Vim package management are:

To set up package management in Vim, create the following folder:

$ mkdir ~/.vim/pack/<key>

Where <key> can be anything; a GitHub handle, a username, or a category. For most cases, a GitHub username should suffice.

Within the <key> directory create another two directories:

The start directory holds plugins that are loaded on start up. The opt directory holds plugins that can be loaded manually via :packadd.

Using Git submodules to manage plugins

Packages can contain version controlled repositories. This means if you have a Git repository version controlling your .vimrc file and .vim directory, Git submodules can be used to manage plugins.

When cloning the Git repository, plugins can be installed by updating the submodules with the following commands:

$ git submodule init
$ git submodule update

Installing a plugin

A Git submodule is installed like so:

$ git submodule add .vim/pack/<key>/start/editorconfig-vim
$ git add .vim/pack/<key>/start
$ git commit -m "Add EditorConfig Vim plugin"

The folder that the submodule is installed under can be anything but I find it easier to use the repository name as the folder name.

Removing a plugin

There may come a time when a plugin is no longer needed. Removing a plugin means removing the Git submodule:

$ git submodule deinit -f -- .vim/pack/<key>/start/editorconfig-vim
$ rm -rf .git/modules/.vim/pack/<key>/start/editorconfig-vim
$ git rm -f .vim/pack/<key>/start/editorconfig-vim