Using Neovim snap as default editor

In order to run the current version of Neovim on Ubuntu 23.10 I installed version 0.9.4 as a snap package.

In zsh.rc I set the alias nv to snap run nvim and it works just fine, but my default editor is still set to the older version of Neovim and I can’t change that because the snap does not appear as an option when I run sudo update-alternatives --config editor.

When I do a git commit the old Neovim version pops up to write the commit message and complains that it can’t run the plugins (like TreeSitter) that run on the snap version. Not a big problem but annoying. Also, I use ZSH and when I type nv filena,,, (with a partial file name) I no longer get the autocomplete that I used to on a partial file name.

The snap version picks up the configuration in .config/nvim/ just like the older version of Neovim does.

Is there a way to get Linux to offer the snap version of Neovim as an option to set as my default editor?

My apologies if this is more of a Linux question than a Neovim question but I’m hoping some Neovim user who has dealt with this can help.

Thanks

In case someone is having the same issue it turns out this is a two-step process:

  1. To add the snap version of Neovim as a choice of editors
sudo update-alternatives --install /usr/bin/editor editor /snap/bin/nvim 1111

(thanks to StackExchange)

  1. Edit .gitconfig to set /var/snap/nvim as the editor for commits.

Nice that you find a solution, but the issue is not the .gitconfig.
You should sudo snap alias nvim editor instead or running the 2nd step. The 1st step is correct.

The change in the .gitconfig is actually shadowing the /usr/bin/editor but just for GIT stuff. You will find issues if trying anything that goes for /usr/bin/editor.

Snap links everything to the same binary, that goes bad with update-alternatives stuff. Making an “alias” allows it to recognize editor as nvim and choose the correct installed snap.