Environment: CentOS 8
Question: When I enter sudo crontab -e
it opens in Vim. However Nano is set as the default editor and for every other type of file it is used as expected. Why might this be? Is there a way around this?
Background: I followed these steps to make Nano the default editor.
# nano /root/.bashrc
I added these lines and saved the file.
export EDITOR='nano'
export VISUAL='nano'
This is what the entire file consists of.
# .bashrc
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
export EDITOR='nano'
export VISUAL='nano'
I used this command to make the change active.
# source /root/.bashrc
/root/.bashrc
is executed only if a shell is started under the root account. Executing a command withsudo
usually does not invoke a shell so the file is not used.sudo
would keep the environment variableEDITOR
if it is set for the calling user. So that is the solution to your problem: