As you know, the recommended way for editing the/etc/sudoers file is with visudo. Visudo opens the /etc/sudoers file with the default text editor, and warns you if you save code with errors.
Visudo reads the SUDO_EDITOR, VISUAL and EDITOR variables, in this order, when choosing the text editor for editing /etc/sudoers. So, you can set nano, for example as your visudo editor and use vim as your default text editor.
Examples for setting popular text editors for visudo:
1. Vim: /usr/bin/vim
$ export SUDO_EDITOR="/usr/bin/vim"
Making the setting persistent:
$ echo 'SUDO_EDITOR="/usr/bin/vim"' >> ~/.bashrc
2. Nano: /usr/bin/nano
$ export SUDO_EDITOR="/usr/bin/nano"
Making the setting persistent:
$ echo 'SUDO_EDITOR="/usr/bin/nano"' >> ~/.bashrc
3. JOE: /usr/bin/joe
$ export SUDO_EDITOR="/usr/bin/joe"
Making the setting persistent:
$ echo 'SUDO_EDITOR="/usr/bin/joe"' >> ~/.bashrc
4. Emacs: /usr/bin/emacs
$ export SUDO_EDITOR="/usr/bin/emacs"
Making the setting persistent:
$ echo 'SUDO_EDITOR="/usr/bin/emacs"' >> ~/.bashrc
If you are using zsh, replace ~/.bashrc with ~/.zshrc and for ksh replace ~/.bashrc with ~/.kshrc.
Leave a Reply