Lockfiles for your Vim Plugins
I recently decided to update my Vim plugins after a long time － bad move. After a single
:PlugUpdate command, I suddenly found my theme broken and even other plugins like
Airline not working as expected.
Though it was easy to figure out that something had broken in a newer version of the
material theme I was using, it took me a while to pinpoint the exact
commit responsible in the repo and revert back to it. Fortunately, the only thing broken
was the theme and not another feature that would hinder my work or productivity
So I started wondering － No plugin or dependency manager for a modern programming
language goes without a locking system. There is
Gemfile.lock for Ruby,
mix.lock for Elixir － so why isn’t it the same for
plugins for text editors like Vim, VS Code or Atom?
I didn’t find a decent answer, but at least for
vim-plug (my plugin manager
for Vim), I found a handy command called
:PlugSnapshot that generates
an executable Vim-script snapshot of all the currently installed plugins.
This isn’t a “lockfile” per se, but pretty close to one. To generate it, you can call the command along with the location to save it as an argument:
To restore plugins from a previously generated lockfile/snapshot, you can run this in your shell:
$ vim -S ~/.dotfiles/Vim/plug.snapshot
Or within Vim:
If you track the snapshot in Git or another VCS, like I do, you can easily diff the snapshot to previous versions if something breaks or changes unexpectedly.
Since the snapshot isn’t automatically generated whenever plugins are updated, it’s easy to forget to call it or even accidentally save it to a different path.
It’s a good thing it’s Vim, so we can define a custom command to do it for us:
command UpdatePlugins \ PlugUpdate | PlugSnapshot! ~/.dotfiles/Vim/plug.snapshot
Now whenever you run
:UpdatePlugins in Vim, it’ll automatically update the snapshot as