Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Editing Files  ›  Capstone Project

Nano — The Editor That Shows Its Keys

Nano 12 minNano has no modes, so typing inserts text, and every command is a Ctrl or Alt shortcut listed at the bottom of the screen.

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.txt

As 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 ^X is Ctrl+X.
  • M- means Meta, which is usually Alt (or Esc on some keyboards). So M-U is 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.

Asha moves a line in her notesStep 1 of 5
  1. 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.

quick drill

In Nano's shortcut list, what does ^X mean?

quick drill

Asha opens a file in Nano and types a word. What happens?

quick drill

Which shortcut saves the file without quitting?

quick drill

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 and M- means Alt.
  • ^O saves, ^X exits, ^K cuts a line and ^U pastes it. Avoid habits from other editors like Ctrl+S and Ctrl+Z.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainNano or Vim?

Explain how to open a file in Nano, move one line to another place, save and exit. Then say when you would choose Nano over Vim.