Dynamically reloading Neovim

I riced too much

While writing my “shell based desktop environment”, more specifically its dynamic themes feature, I realized that, unlike regular Vim, Neovim doesn’t have flags likes --servername, --remote-send and such, so there was no way I could send a message to all Neovim instances to reload themselves. This problem remained unsolved for a month or so.

Then, while I was a bit bored, I read Neovim’s news page. Scrolling down a bit, I found this:

nvr now supports the Vim “clientserver” options –servername, –remote, etc. nvr is perfect for communicating with a parent nvim instance from a :terminal buffer.

Bingo, that’s exactly what I need!

To make all Neovim instances listen to some socket whose path I know, I made a shell function:

nvim() {
	# Set the name of neovim's socket
	local fn="$(mktemp -u "/tmp/nvimsocket-XXXXXXX")"
	NVIM_LISTEN_ADDRESS=$fn /usr/bin/nvim $@

Now, to reload all Neovim instances I can run:

for nvim_inst in /tmp/nvimsocket-*; do
	nvr --servername "$nvim_inst" --remote-send '<Esc>:so $HOME/.config/nvim/init.vim<CR>' &