How to change visudo editor

I want to change the editor of visudo from nano to vim;
I have read the Arch wiki:
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?


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
$ sudo -s
# echo $EDITOR

why und how can I change this?


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
visudo behaves as wished.
many thanks for your help!!

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.


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