Nano — The Editor That Shows Its Keys
Not every edit is worth learning a new way of thinking. When Asha just needs to change one line in a config file, Nano is the quickest way in. It has no modes, and a list of shortcuts sits at the bottom of the screen the whole time.
The rule
Nano types what you press; Ctrl does the rest.
$ nano ~/garden/notes.txtAs soon as the file opens, you can type and the text goes in, just like a normal text box. Every command is a key combination, and the most useful ones are listed along the bottom edge. You only need to know how that list is written:
^means Ctrl. So^Xis Ctrl+X.M-means Meta, which is usually Alt (or Esc on some keyboards). SoM-Uis Alt+U.
The keys you'll use every day:
| Shortcut | Nano calls it | Does |
|---|---|---|
^O |
Write Out | save the file; press Enter to confirm the name |
^X |
Exit | quit, asking whether to save if there are changes |
^K |
Cut | cut the whole current line |
^U |
Paste | paste the last cut text |
^W |
Where Is | search |
^_ |
Go To Line | jump to a line number |
M-U |
Undo | undo the last change |
^G |
Help | show every shortcut |
When you press ^X with unsaved changes, Nano asks "Save modified buffer?" and you answer Y or N. If you say Y, it shows the filename; press Enter to keep it.
The shortcut
Read the bottom two lines before you do anything else. Whatever you want to do is probably listed there. Just translate ^ to Ctrl as you read.
Open
nano ~/garden/notes.txt. She can type straight away.
Nano versus Vim: Nano is quicker to learn and fine for small edits. Vim takes longer to learn but is much faster for heavy editing, and some form of vi is available on almost every Unix-like system. Many commands open whichever editor the EDITOR environment variable names, which you'll meet in the next section, so you can choose your favourite.
A classic Nano trap is pressing Ctrl+S or Ctrl+Z out of habit. Depending on the version and your terminal, Ctrl+S may save or may freeze the screen (Ctrl+Q unfreezes it). Ctrl+Z may pause Nano and drop you back at the shell, where fg brings it back. Stick to ^O and ^X.
Drills
Answer fast — trust the rule.
In Nano's shortcut list, what does ^X mean?
Asha opens a file in Nano and types a word. What happens?
Which shortcut saves the file without quitting?
How do you move a line in Nano?
Remember
- Nano types what you press; Ctrl does the rest.
- Read the bottom two lines.
^means Ctrl andM-means Alt. ^Osaves,^Xexits,^Kcuts a line and^Upastes it. Avoid habits from other editors like Ctrl+S and Ctrl+Z.
