1

I want to set nvim(Neovim) as my default editor, I have tried to edit my .bashrc and add this two line:

export EDITOR=nvim
export VISUAL=nvim

and then

$ source .bashrc

but it didn't work. Proof:

$ sudo visudo
visudo: no editor found (editor path = /usr/bin/vi)

How can I set that correctly?

manungsa
  • 125
  • 9

2 Answers2

2

sudo by default sanitizes your environment: variables you set for your user account won't be visible in the process started by sudo. You can run sudo with the -E (--preserve-env) flag:

sudo -E visudo

You can add VISUAL and EDITOR to the list of environment variables that sudo preserves by default by editing /etc/sudoers and adding:

Defaults    env_keep += "VISUAL EDITOR"

Or you can set EDITOR and VISUAL in root's .bashrc file.

larsks
  • 32,449
  • 5
  • 54
  • 70
1

As an alternative to --preserve-end and env_keep you can set environment variables used by sudo and all user sessions in the /etc/environment file.

$ cat /etc/environment
EDITOR=nvim
VISUAL=nvim
don_aman
  • 1,353
  • 3
  • 9