Skip to content
ALB Wiki

Editors

This is an old revision of this page — revision 1 (2026-10-25 14:50:33 UTC). It may differ from the current revision.

Every system task ends at an editor — every config file, every script, every fstab, every authorized_keys. Two editors are guaranteed: vi (the POSIX-mandated one — present on every Unix ever) and nano (the kind one). This chapter teaches vi fluency as a survival skill and a fluency, nano as the friendly default, and when each is the right tool.

vi — the one that's always there

Vi's core trick: modes — i to insert, Esc back to normal, where every key is a command. The discipline feels alien for a day, then becomes how you think:

ESC — normal mode (the home base)
i / a / o — insert before / after / new line
:w — write · :q — quit · :wq — save+quit · :q! — force-quit
:x — save+quit · ZZ — save+quit
dd — delete line · yy — yank · p — paste · u — undo · Ctrl-R redo
0 / $ — line start/end · gg / G — file start/end
/pattern — search · n — next · ? — search back
:%s/old/new/g — sed inside the editor
:wq — the command every tutorial drills

The verbs compose: d + motion = delete (dw word, d$ to end, d5d five lines); y + motion = yank; c + motion = change. 5dd deletes five lines; ci" changes inside quotes; v selects visually; . repeats the last command. The language is grammar — verb + motion — and fluency is learning to speak it.

vim — vi's empire

vim adds syntax highlighting, multiple files, splits, plugins — on most Linuxes vi is vim in compatible mode. vimtutor is the built-in tutorial — 20 minutes, genuinely sufficient. The survival set for config work: i/Esc, :wq, dd, u, /, :set number. Everything else is depth.

nano — the kind one

nano file
Ctrl-O — write out · Ctrl-X — exit · Ctrl-W — find
Ctrl-K — cut line · Ctrl-U — uncut · Ctrl-G — help

The shortcuts are printed at the bottom — the editor that explains itself. For quick edits and for anyone not living in the terminal, nano is correct. /etc/alternatives/distro defaults set EDITOR/VISUAL — export EDITOR=nano makes it the system's default (which is what visudo, crontab -e, git commit messages invoke).

The others worth knowing

  • ed — the line editor — ancient, scriptable, the ancestor of sed and vi's : commands — ed survives in POSIX
  • sed -i — editing without an editor — sed -i.bak 's/a/b/g' is the scripted edit
  • emacs — the other giant — a lisp environment that edits text
  • code/nvim/helix — the moderns — VS Code, Neovim, Helix

The config-file craft

Real editing is config work — /etc/fstab, sshd_config, .bashrc:

sudoedit /etc/fstab         # edits as user, writes as root — safer than sudo vi
vi /etc/ssh/sshd_config     # the classic
nano ~/.bashrc

The disciplines: back up before editing (cp file file.bak), learn the file's syntax (comments #, tabs vs spaces where it matters — /etc/fstab whitespace, Makefile tabs), syntax-check after (sshd -t, visudo checks sudoers automatically, mount -a tests fstab). A broken /etc/fstab boots to emergency mode; a broken sudoers locks out sudo — know the check command before saving.

Where editors go wrong

SymptomCause
Typing produces commands, not textvi in normal mode — i
:wq didn't quitStill in insert — Esc first
sudo vi file leaves root-owned filessudoedit or sudo -e is cleaner
git commit opens an alien editorexport EDITOR=nano
vi's colors unreadable:syntax off, or TERM broken
Saved but the change didn't takeThe file needed a service restart / re-source

Exercises

  1. vimtutor — once through, honestly.
  2. Edit a scratch file: dd a line, u undo, /search, :%s/x/y/g.
  3. export EDITOR=nano; crontab -e — see the default take effect.
  4. sed -i.bak 's/a/b/g' a file — the no-editor edit.
  5. Open /etc/fstab in vi — read-only practice, :q! out.

See also

Categories: Editors · Handbook · Linux · Linux Handbook
This page was last edited 2026-10-25 14:50:33 UTC by ALB Team. What links here