How to change default bash editor from vim to nano -Linux, CentOS
Introduction
This short tutorial will demonstrate how to change default command line (bash) editor in Linux and Unix type operating system. Most of the Linux distribution comes with vim or vi as default bash editor. Both are powerful editor, but I don’t like their interface. Here I’m going to demonstrate changing bash editor from vim to nano in CentOS 7.3 environment. Nano (developer’s link) is an advance command line editor with better interface. Same method is applicable for any other Linux or Unix distribution with bash as default command line.
Disclaimer: I’m running all installation commands as root user. So, I’m not using sudo. If you’re running a non root user with super user privilege append all installation and other necessary commands with sudo.
Difficulty: Easy Time Require: Less than 5 minutes.
Installing nano
In RHEL and CentOS nano is present in base repository and can be installed with yum as follows
yum install nano |
Same way, you can install nano in Debian and Ubuntu using apt-get
apt-get install nano |
Finding the binary location
You can find executable binary of any installed package using which as follows.
which nano Output: /usr/bin/nano |
This will give the location of executable binary location, here “/usr/bin/nano”
If which which is not installed install it as follows
yum install which or apt-get install which |
Changing bash editor from vim or vi to nano
For Individual User:
Edit or create “.bash_profile” or “.bashrc” in user’s home directory with your favorite editor
nano ~/.bash_profile or nano ~/.bashrc |
Append the file with following
export VISUAL=/usr/bin/nano export EDITOR=”$VISUAL” |
A sample configuration file is as follows
From next time when you log into the system you’ll find nano as your default editor.
Changing system wide configuration
To change system wise default bash editor edit “/etc/bashrc” file and append it as follows
nano /etc/bashrc |
export VISUAL=/usr/bin/nano export EDITOR=”$VISUAL” |
Note: For specific user, system wise bash configuration is overridden with individual user’s configuration.
Checking the configuration
You may want to let sure that it’s changed. To check the new default editor first logout from the existing bash session.
exit |
Then start a new session and try to edit crontab with the following command.
crontab -e |
If everything goes right you’ll find the nano interface as crontab editor instead vim or vi. If this is not in your case please follow the above steps once again
Serverlog thanks you for reading. For any difficulty please don’t forget to leave your comments bellow.