nano Command Cheat Sheet
nano is a small, free, and friendly editor which aims to replace Pico. It is the default editor on many simple Linux systems.
Synopsis
nano [OPTIONS] [[+LINE,COLUMN] FILE]...
Basic Shortcuts
Control key is represented by ^ or Ctrl.
| Key | Action |
|---|---|
^O |
Write Out (Save) |
^X |
Exit (Prompts to save) |
^R |
Read File (Insert another file) |
^W |
Where Is (Search) |
^\ |
Replace |
^K |
Cut Text (Cut line) |
^U |
Uncut Text (Paste) |
^J |
Justify (Wrap paragraph) |
^C |
Cursor Position (Line/Col info) |
^_ |
Go to Line |
Editing Tricks
Cut/Paste Blocks
Nano doesn't have standard selection (Shift+Arrows) by default in older versions.
1. Move to start.
2. Press M-A (Alt+A) or ^6 to Set Mark.
3. Move arrow keys to select text.
4. ^K to Cut.
5. ^U to Paste.
Search and Replace
- Press
^\(Ctrl + Backslash). - Enter search string.
- Enter replacement string.
- Confirm each (y/n) or All (a).
Command Line Options
View Mode (-v)
Open file read-only.
nano -v config.txt
No Wrap (-w)
CRITICAL for config files. Prevents nano from adding newlines to long lines.
nano -w /etc/fstab
Show Line Numbers (-l)
nano -l script.py
Auto-Indentation (-i)
nano -i code.c
Configuration (~/.nanorc)
Make settings permanent by editing ~/.nanorc.
set linenumbers
set mouse
set smooth
set tabsize 4
set nowrap
include "/usr/share/nano/*.nanorc"
Notes
- Meta Key:
M-usually meansAltorEsc. e.g.,M-U(Alt+U) works Undo (in newer versions). - Undo/Redo:
Alt+U(Undo),Alt+E(Redo) - Available in modern Nano versions.