Vim Plugins, the Right Way

It’s good to be a software minimalist (and a minimalist in general). This is how to be one when it comes to Vim plugins (aside from not using plugins, of course).

Why Plugin Managers?

Vim’s directory hierarchy is traditionally something like this.

.vim/
├── autoload/
├── colors/
├── doc/
├── ftplugin/
├── indent/
├── plugin/
├── spell/
├── syntax/
└── undo/

It looks quite sensible. Plugins follow this hierarchy, with their .vim files going into plugins/ (and sometimes autoload/), help files in doc/, etc. This makes uninstalling or updating plugins a real pain.

Plugin managers solve this problem by abstracting this hierarchy, so you don’t have to think about it.

How to Get Rid of Plugin Managers?

Vim 8 introduced the notion of a package (see :h packages). Plugins (i.e. their entire directory hierarchy) can live in .vim/pack/plugins/start/plugin_name/ and Vim will add this to its runtime path. (The plugins/ directory can actually be named however you like.)

This is pretty great, because now our plugins can be kept under version control. Getting them is just a clone, they can be easily updated and they can be rolled back.

However, the .vim/ directory is probably already under version control, along with the rest of the dotfiles.

To deal with this: instead of cloning, use git submodule add repository.git. Then just keep it up to date by pulling it every so often. To update all plugins, git submodule foreach git pull.

When cloning the dotfile repository, use the --recursive flag to get the submodules as well. Alternatively, clone as normal and then initialise and update the submodules with git submodule init && git submodule update.

Run :helptags ALL to generate helptags for all plugins.

I think so. Some might disagree and argue for using git-subtree instead.

I don’t believe this is the right way any more. I now use minpac for Vim and paq for Neovim.

How to Remove a Submodule?

There’s a lot of disinformation out there. Just git rm path/to/submodule, like the docs say.

The deletion removes the superproject’s tracking data, which are both the gitlink entry and the section in the .gitmodules file. The submodule’s working directory is removed from the file system, but the Git directory is kept around as it to make it possible to checkout past commits without requiring fetching from another repository.

Where Are Your Dotfiles?

.dotfiles/
├── vim/.config/vim/vimrc
└── nvim/.config/nvim/init.lua