$EDITOR variable

From Linux Bash Shell Scripting Tutorial Wiki
Jump to navigation Jump to search

The $EDITOR defines the user's preferred utility to edit text files on Linux or Unix-like systems. It is an environment variable.

Purpose

This variable is used to specify the screen-oriented text editor. Generally, you will want to set it to the same value as the $VISUAL variable.

The user's preferred utility to edit text files set by $EDITOR
The user's preferred utility to edit text files set by $EDITOR

Viewing the $EDITOR variable

Try echo command or printf command to display the current text editor set to edit files by default:

echo "$EDITOR"
printf "The current value of \$EDITOR is %s\n" "$EDITOR"

Setting the $EDITOR variable

The syntax is as follows for Bash:

# Set it to nano
export EDITOR=nano

# OR Set it to emacs
export EDITOR=emacs

# Verify it
printf "The current value of \$EDITOR is %s\n" "$EDITOR"

Alternatively, you can use the following syntax:

# Set it to micro
EDITOR=micro; export EDITOR

# Verify it
printf "The current value of \$EDITOR is %s\n" "$EDITOR"

Setting the EDITOR permanently

First, find out your current shell name:

echo "$SHELL"
ps -p $$

Then depending on the shell you can set $EDITOR as follows:

Set a text editor type to vim/vi or ed as per your needs
Shell Linux/Unix command Setting the text editor type permanently in this file in your home directory
bash export EDITOR=ed .bash_profile
csh setenv EDITOR ed .cshrc or .login
ksh export EDITOR=ed .profile
sh EDITOR=ed; export EDITOR .profile
tcsh setenv EDITOR ed .tcshrc or .login
zsh export EDITOR=ed .zshrc

Here is a one-liner to set up a text editor type to ed on Linux server when using Bash:

echo 'export EDITOR=ed' >> $HOME/.bash_profile

See also