Editors
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
sedand vi's:commands —edsurvives 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
| Symptom | Cause |
|---|---|
| Typing produces commands, not text | vi in normal mode — i |
:wq didn't quit | Still in insert — Esc first |
sudo vi file leaves root-owned files | sudoedit or sudo -e is cleaner |
git commit opens an alien editor | export EDITOR=nano |
| vi's colors unreadable | :syntax off, or TERM broken |
| Saved but the change didn't take | The file needed a service restart / re-source |
Exercises
vimtutor— once through, honestly.- Edit a scratch file:
dda line,uundo,/search,:%s/x/y/g. export EDITOR=nano; crontab -e— see the default take effect.sed -i.bak 's/a/b/g'a file — the no-editor edit.- Open
/etc/fstabin vi — read-only practice,:q!out.