Much of Linux is configured with plain text files. Servers often have no graphical desktop, so you need an editor that runs inside the terminal. A word processor will not do: it stores formatting along with your words, while configuration files need plain text only.
The common choices
- nano is small and shows its main shortcuts at the bottom of the screen. It is easy to start with.
- Vim is an improved version of the old
vieditor. It works with modes: the same key does different things depending on the mode you are in. - Emacs is a large, extensible editor. You type text directly and give commands with Control and Alt key combinations.
What is already installed
Some form of vi is present on most Linux systems, which is a good reason to learn its basics. POSIX, the Unix standard, describes vi. Do not assume that Emacs is there, and minimal images and containers may lack nano or even vi.
Check what you have:
$ command -v vi vim nano emacs
/usr/bin/vi
/usr/bin/nanoOnly the programs that exist are listed. Here vim and emacs are missing.
On Debian and Ubuntu, vi may be a cut-down build called vim.tiny. Install the full editors with your package manager:
sudo apt install vim emacs-nox # Debian, Ubuntu
sudo dnf install vim-enhanced emacs-nox # Fedora and relativesemacs-nox is the build without graphical support.
Choosing a default editor
Many programs open an editor for you, for example crontab -e. They commonly look at the VISUAL and EDITOR environment variables, usually preferring VISUAL.
$ export VISUAL=vim
$ export EDITOR=vim
$ echo "$EDITOR"
vimThis lasts for the current shell session. To keep it, add the export lines to your shell startup file, such as ~/.bashrc.
Some programs have their own rules. Debian-based systems also offer sudo update-alternatives --config editor to pick the system-wide editor command.
Editing system files
For files owned by root, sudoedit /etc/hosts is safer than running a whole editor as root. It copies the file, lets you edit the copy as yourself, then writes it back. It chooses the editor from SUDO_EDITOR, VISUAL or EDITOR, within the limits of the system's sudo policy.
You do not have to pick a side between Vim and Emacs today. Learn enough of one to open, change, save and quit with confidence. Then try the other if you are curious.
Try it
- Run
command -v vi vim nano emacsto see what your system has. - Print your current setting with
echo "$EDITOR". An empty line means it is not set. - Set it with
export EDITOR=nanoand print it again. - For a live Linux shell, open the files and links lab.
Check your understanding
Text Editors
All 5 sections ยท no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.