How to change visudo editor

I want to change the editor of visudo from nano to vim;
I have read the Arch wiki:
https://wiki.archlinux.org/title/Sudo#Using_visudo
but nothing seems to work: visudo always launches nano
(I’m much more familiar with vim/vi than with nano).
Can it be that nano is hardcoded into visudo?

Hans

su # <<< Enter password
EDITOR=vim visudo

Works here.

su #enter root password
export EDITOR=vim

You could add

Defaults editor=/usr/bin/vim

to sudoers file to make it permanent.

I have done exactly this but visudo launches nano, not vim.
The best “solution” for me is:
$ sudo -s
# EDITOR=vim visudo

all I want is a one-liner like
sudo visudo
and visudo launching vim, not nano

fact is: sudo changes to nano and I don’t know why:
$ export EDITOR=vim
$ echo $EDITOR
vim
$ sudo -s
# echo $EDITOR
nano

why und how can I change this?

Hans

Check your bashrc / /etc/environment / .profile to find where $EDITOR is set and change it.

1 Like

/etc/environment was it.
after the change from
EDITOR=nano
to
EDITOR=vim
visudo behaves as wished.
many thanks for your help!!
Hans

1 Like

Please mark @xircon’s post as solution by clicking on … and checking the box.
This would help other users looking for solution to similar issue to more easily find one.

2 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.