How to change the default text editor in bash, zsh and ksh

The default editor in Debian/Ubuntu/Linux Mint is Nano. I will change it to ViM, for bash, zsh and ksh.

Watch Free Movies

Both, the EDITOR and VISUAL environment variables are used for setting the default editor. Set them to the same value, in order not to have problems with some applications that know how to open files in the default text editor.

The export command is used to make a local variable global.

Syntax: export EDITOR=/path/to/new/editor
Syntax: export VISUAL=/path/to/new/editor

You can change the default editor temporarely – your modifications will be discarded at the first logout:

$ which vim
/usr/bin/vim
$ export EDITOR=/usr/bin/vim
$ export VISUAL=/usr/bin/vim

Changing the default editor persistenly:

A setting is persistent if it is saved in a file. For changing the default editor for all the users in the system (globally), you should append the new setting to /etc/profile:

# echo "export EDITOR=/usr/bin/vim" >> /etc/profile
# echo "export VISUAL=/usr/bin/vim" >> /etc/profile

If you want to set a default editor for a certain user only, you should modify that user’s .profile file (his ~/.profile) or the user’s shell configuration file:

~/.bashrc for the bash shell

~/.zshrc for the Z shell

~/.kshrc for the Korn shell

In bash:
$ echo "export EDITOR=/usr/bin/vim" >> ~/.bashrc
$ echo "export VISUAL=/usr/bin/vim" >> ~/.bashrc

In zsh:
$ echo "export EDITOR=/usr/bin/vim" >> ~/.zshrc
$ echo "export VISUAL=/usr/bin/vim" >> ~/.zshrc

In ksh:
$ echo "export EDITOR=/usr/bin/vim" >> ~/.kshrc
$ echo "export VISUAL=/usr/bin/vim" >> ~/.kshrc

Related reading: How to set the default editor in csh and tcsh.

Scroll to Top