$ nano notes.txt$ cat notes.txteggsbreadmilknanovimeggsbreadmilk^O Write Out ^X ExitLinux kerneldisk · notes.txteggsbreadmilknano notes.txtmilk^Xcat notes.txt
Back: user space (terminal, editor, buffer). Middle: the Linux kernel. Front: the disk with notes.txtTokens: typed commands and keys, and envelopes that carry the file's text through the kernelUser space at the back: the terminal, the editor and its buffer, the editor's copy of the file in memory. The Linux kernel in the middle. The disk in front, holding notes.txt. nano reads the file through the kernel into the buffer; typing changes only the buffer; Ctrl+O writes the buffer back through the kernel to the disk. In vim, :q! throws the buffer away and the disk keeps its text. While nano or vim runs, it draws the buffer over the whole terminal window. The figure keeps the terminal card and the buffer apart so you can see both.

Editors and buffers

  1. A text editor is a program for changing the words in a file. In a terminal there is no mouse menu, so you steer it with keys. nano is the friendliest one; vim is powerful but has modes.

Editing with nano

vim and its modes

What happens

;; step 1/10 · editor
text editor   a program that changes the text in a file
in a terminal no menus to click: you steer with keys
  nano        simple: shortcuts listed on screen
  vim         powerful: keys mean different things
              in different modes

While nano or vim runs, it draws the buffer over the whole terminal window. The figure keeps the terminal card and the buffer apart so you can see both. The C library turns open() into the openat system call on Linux. A program may read or write in more than one call; the figure shows one of each.