Keyboard shortcuts
^O= Ctrl+O,M-W= Alt+W. This is printed at the bottom of the screen — check there.
A friendly console editor — save, quit, search, for editing config files.
nano file
open/create a file
sudo nano /etc/hosts
edit a system file
nano +25 file
open positioned at line 25
nano -w file
don't wrap long lines
Ctrl+O save Ctrl+X quit
Ctrl+W search Ctrl+\ replace
Ctrl+K cut a line Ctrl+U paste Ctrl+6 select
nano is a simple editor: you type right away, with no modes (unlike
vim). The bottom of the screen shows keyboard shortcuts, where ^ means
Ctrl and M- means Alt. A good choice for quick config edits.
Globally — /etc/nanorc. Highlighting for many formats works out of the
box.
| Option | What it does | Example |
|---|---|---|
-w --nowrap |
Do not soft-wrap long lines — important when editing config files. | nano -w /etc/nginx/nginx.conf |
-l --linenumbers |
Show line numbers. | nano -l file |
+N |
Open the file positioned at line N. | nano +25 file |
-c --constantshow |
Always display the current cursor position. | nano -c file |
-i --autoindent |
Auto-indent — a new line inherits the previous line's indent. | nano -i file |
-m --mouse |
Enable mouse support. | nano -m file |
-B --backup |
Keep a backup copy of the file (suffixed ~) when saving. | nano -B file |
Nothing found. Try a shorter query.
^O= Ctrl+O,M-W= Alt+W. This is printed at the bottom of the screen — check there.
The editor only writes the file. The service needs to reread its config
(systemctl reload/restart).
You didn't open it with sudo. Quit (Ctrl+X, without saving) and
sudo nano file.
nano -w file (or set nowrap) turns off soft wrapping, so long config
lines don't look visually "broken".
Terminal paste can be slow with large blocks; for configs this is usually
fine. For indentation, use set tabstospaces.
For servers, know at least the minimum of vim — it's always there; nano
sometimes isn't installed (sudo apt install nano).
Found an inaccuracy? Report an error in the article