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.

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
$ 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.

Tagged with: , , , , , , ,
Posted in The Linux and Unix Articles!
3 comments on “How to change the default text editor in bash, zsh and ksh
  1. steven says:

    how can i check to make sure that i’ve set the default editor correctly?

  2. steven says:

    nevermind, i just discovered i can print out the default editor variable like so:
    $ echo $EDITOR

    i can also make sure there are no errors when i just open the terminal again.

  3. Oleg says:

    Thanks a lot for your tip

Leave a Reply

Your email address will not be published. Required fields are marked *




Subscribe to get the latest Linux news and how to guides directly on your e-mail!