Notes from switching to vim.pack

I am a long term tmux + neovim enthusiast, and for the last 10 or so years, I’ve been using vim-plug to manage my vim dependencies. I recently learned that very similar functionality was added to neovim core. The vim.pack interface provides a built-in package manager for vim plugins. Its feature set overlapped very well with my usage of vim-plug. I was able to convert my existing configuration over to vim.pack quickly with some simple search and replace macros.

After getting vim.pack setup, the docs recommend to :restart. After restarting, neovim automatically started an installation process of my packages. I appreciate the care the neovim team took to build a review and confirm experience. I really like the UX of this, and even better is that vim.pack generates a lock file that pins each package to a specific SHA. Having a lockfile makes getting reproducible states across multiple machines possible which was a nice upgrade.

Defining packages

Packages are added via URLs, and can optionally defined tags/branches to follow:

Show Plain Text
  1. vim.pack.add({
  2.   'https://github.com/tpope/vim-ragtag',
  3.   'https://github.com/tpope/vim-surround',
  4.   'https://github.com/tpope/vim-unimpaired',
  5.   'https://github.com/Townk/vim-autoclose',
  6.  
  7.   'https://github.com/duff/vim-scratch',
  8.   'https://github.com/markstory/vim-zoomwin',
  9.   -- Project Drawer
  10.   {src = 'https://github.com/lambdalisue/fern.vim', version = 'main'},
  11.   'https://github.com/lambdalisue/nerdfont.vim',
  12.   ...
  13. })

Each time you :restart the new package install flow will take place. My requirements are pretty simple, but you can also specify version ranges constraints with vim.version.range(). For me, the lock file was saved into ~/.config/nvim/nvim-pack-lock.json which is where I mount my vim-files repository. This convienently makes the lockfile easy to integrate with version control. Packages on the other hand, were installed into ~/.local/share/nvim/site/pack/ making them local to the machine straightforward to find should files need to be cleared manually.

Updating packages

After a package has been installed, you can refresh a single package or all packages:

Show Plain Text
  1. vim.pack.update({'vim-ragtag'})

When the update is complete, a new buffer is opened with the output of the operations taken. If there were no changes made you aren’t prompted to interact with packages. I quite like this user interface and think it is a wonderful way to interact with a package manager for vim.

Removing packages

When it is time to remove a package, updating your vim.pack.add() call and what is loaded on disk are two separate steps. My workflow is to use vim.pack.del('package-name') and then update my vim config in the same session.

Overall, I’m quite happy with this addition to neovim. It solves all of my requirements, and lets me simplify more of my vim configuration. If you’re interested in how I have vim configured, it is available on GitHub.

Comments

There are no comments, be the first!

Have your say: