Join my free Bash scripting course on Udemy 👀

Set your default terminal editor in Linux

May 21, 2022  ‐ 2 min read

While others may have this the other way around, I feel clumsy in everything that doesn't have vim-like keybindings. Mainly speaking about you here nano.

Luckily we can configure our preferred terminal editor for our shell environment. Whether it is nano, vim, emacs or something exotic. This setting is taken from the EDITOR and VISUAL environment variables.

The difference between the EDITOR and VISUAL variables is that the editor you set to EDITOR should be able to work with more advanced interactive terminal functionality.

These variables are set for your shell environment, so depending on whether you use bash, zsh or fish you should edit the correct shell configuration file. For bash that is ~/.bashrc, and for zsh ~/.zshrc.

Set nano as your editor in bash

Assumed you use bash as your shell, add the following to your ~/.bashrc file to set nano as your terminal editor.

# ~/.bashrc
export EDITOR='nano'
export VISUAL='nano'

Set vim as your editor in bash

Assumed you use bash as your shell, add the following to your ~/.bashrc file to set vim as your terminal editor.

# ~/.bashrc
export EDITOR='vi'
export VISUAL='vim'

Set emacs as your editor in bash

Assumed you use bash as your shell, add the following to your ~/.bashrc file to set emacs as your terminal editor.

# ~/.bashrc
export EDITOR='emacs -nw'
export VISUAL='emacs'