Skip to the workspace
Pebellslearn by building
Terminal Knowledge  ›  Capstone Project

Terminal Editors — Vim, Nano and Emacs

Vim / Nano / Emacs 12 minServers are edited in terminal editors: nano is simplest, Vim is almost always present and works in modes, and Emacs is modeless and powerful but rarely preinstalled.

devops / Terminal Editors — Vim, Nano and Emacs

Explore each scene at your own pace.

01 · The rule

The rule

Terminal Editors — Vim, Nano and Emacs

At 2 a.m. you SSH into web1 to fix one line in the nginx config. There is no graphical editor, no mouse and no VS Code. You get whatever terminal editor is installed, and you need to change the line, save and get out without panic.

The rule

In Vim you are in Normal mode until you ask to type.

Three editors dominate servers:

Nano is the gentlest: you type straight away and the shortcuts are listed at the bottom. Ctrl+O then Enter saves, Ctrl+X exits, Ctrl+W searches.

Vim (or its ancestor vi) is present on almost every Unix-like system, which is why it is worth learning. It is a modal editor:

  • Normal mode (where you start): keys are commands. dd deletes a line, u undoes, /listen searches for "listen", n jumps to the next match.
  • Insert mode: press i and keys type text. Press Esc to go back to Normal.
  • Command line: from Normal, : opens a prompt. :w saves, :q quits, :wq saves and quits, :q! quits and throws away changes.

Emacs is not modal: you type directly and commands use Control or Alt combinations, such as Ctrl+X Ctrl+S to save and Ctrl+X Ctrl+C to quit. It is powerful and extensible but rarely installed on servers by default.

Tools such as git commit, crontab -e and visudo open the editor named in the EDITOR environment variable, so you can choose:

export EDITOR=nano
sudo nano /etc/nginx/sites-available/notes
sudo vim /etc/nginx/sites-available/notes
Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.