One of the key benefits of modern editors like NVim, Vim, or Emacs is the rich plugin ecosystem. After years with Vim, I switched to NVim and was immediately impressed by its plugin landscape. The Lazy plugin manager—available for NVim > 0.8—quickly became my favourite. Lazy simplifies plugin discovery and management. It offers an intuitive interface and powerful commands that make it easy to add, remove, or update plugins.
Auto-Updating Plugins
As I added more plugins, Lazy frequently prompted me to update them. I found myself running updates manually almost every session. Naturally, I wanted to automate this.
Lazy supports execution of custom commands. Its configuration allows binding actions to various events. One useful event is VeryLazy, but more generally, NVim’s autocommand system provides a robust mechanism for triggering code on specific actions. Inspired by a gist by dtr2300, I chose to trigger plugin updates on the FocusLost
event. This means NVim will automatically check for updates whenever I switch to another window—an ideal, non-disruptive moment.
Here’s the Lua code I use:
|
|
Note that some plugins may require a manual reload after updating. Lazy.nvim now supports an experimental :Lazy reload plugin_name
command, but this is not automatically triggered after updates. Reloading works best with plugins that implement a proper deactivate function or are explicitly marked as safe to reload. For others, re-running config functions can cause issues, so use this feature cautiously and check each plugin’s documentation or behavior before relying on it.
The configuration lives in $XDG_CONFIG_HOME/nvim/lua/config/autocmds.lua
1. Depe
-
If unset the
$XDG_CONFIG_HOME
points to$HOME/.config
. ↩︎