I am attempting to use Neovim (nvim) to edit files without requiring sudo privileges, regardless of the file’s permission settings. I’ve tried it with security.sudo, but it does not seem to work. Any idea why?
What happens instead of your desired behavior? If another editor opens, you might have to make sure that $EDITOR variable exists for the root user.
If the behaviour is that nvim opens, but without all you configuration, that is due to fact again that your nvim config is bound to your user (and you are opening files as root instead). I saw people mess before with sudo -e but I would not recommend. Have you used the sudoedit command before (it basically is a wrapper around sudo -e)?
If your editor for the root user is set correctly, this should work.
I have configured Neovim with Home Manager, but I’m encountering an unexpected behavior with environment variables. Despite setting SUDO_EDITOR, SYSTEMD_EDITOR, EDITOR, and VISUAL to "nvim" in my root configuration, the default editor still opens as nano when running commands like sudoedit.
Additionally, echoing $EDITOR returns variable not found. For this matter, not even cli file managers such as nnn work. They will give out the error permission denied for some reason.
Are you running Nixos or another system? That would give additional context.
Aside from on which system you are trying to achieve this, if $EDITOR is unset for root, that is an indicator of where your problem lies.
It might be that you have configured nvim to only be available within you user scope, and that means it won’t be present outside that scope. That is something you haven’t told us yet.