nano — The Simple Terminal Text Editor
Practical guide to nano — edit files in the terminal quickly and without a learning curve, the beginner-friendly editor on every Linux.
nano is the simple, beginner-friendly text editor for the terminal: it ships on virtually every Linux system and is deliberately built so you can start editing without a steep learning curve. The most important commands are always shown in the key bar at the bottom, where ^ stands for the Ctrl key and M- for the Alt/Meta key. Unlike vim there are no modes – you start typing right away and save with Ctrl+O, quit with Ctrl+X. This guide walks you through the key bindings and .nanorc settings that let you work in nano quickly and comfortably.
Opening Files
nano <file> — Open a file for editing (creates it if it doesn't exist).
nano config.yamlnano +<line> <file> — Open a file and jump to a specific line number.
nano +42 script.shnano +<line>,<col> <file> — Open a file and jump to a specific line and column.
nano +10,5 config.phpnano -B <file> — Create a backup of the file before editing (~filename~).
nano -B /etc/nginx/nginx.confnano -R <file> — Open a file in read-only (restricted) mode.
nano -R /etc/passwdnano -l <file> — Show line numbers in the left margin.
nano -l script.pynano -m <file> — Enable mouse support for clicking and scrolling.
nano -m document.txtnano -i <file> — Enable auto-indentation.
nano -i main.gonano -Y <syntax> <file> — Force a specific syntax highlighting language.
nano -Y php config.incSaving & Exiting
Ctrl+O — Write Out (save) the current file. Press Enter to confirm the filename.
Ctrl+O → EnterCtrl+X — Exit nano. Prompts to save if there are unsaved changes.
Ctrl+X → Y → EnterCtrl+X → N — Exit without saving changes.
Ctrl+X → NCtrl+O → new_filename → Enter — Save As: type a new filename when prompted by Write Out.
Ctrl+O → backup.conf → EnterNavigation
Ctrl+A / Ctrl+E — Jump to the beginning / end of the current line.
Ctrl+ACtrl+Y / Ctrl+V — Page Up / Page Down.
Ctrl+VAlt+\ / Alt+/ — Jump to the first / last line of the file.
Alt+\Ctrl+_ (Ctrl+Shift+-) — Go to a specific line number (and optionally column).
Ctrl+_ → 42 → EnterAlt+G — Go to line number (alternative shortcut).
Alt+G → 100 → EnterCtrl+Space / Alt+Space — Move forward / backward one word.
Ctrl+SpaceCtrl+C — Show the current cursor position (line, column, character).
Ctrl+CEditing
Ctrl+K — Cut the current line (or selected text) to the cutbuffer.
Ctrl+KCtrl+U — Paste (uncut) the cutbuffer at the cursor position.
Ctrl+UAlt+6 — Copy the current line (or selected text) without cutting it.
Alt+6Ctrl+K (multiple) — Cut consecutive lines — they accumulate in the cutbuffer.
Ctrl+K Ctrl+K Ctrl+K (cuts 3 lines)Alt+T — Cut from the cursor to the end of the file.
Alt+TCtrl+J — Justify (reflow) the current paragraph.
Ctrl+JAlt+U — Undo the last action.
Alt+UAlt+E — Redo the last undone action.
Alt+ECtrl+\ — Search and replace.
Ctrl+\ → old → Enter → new → Enter → A (replace all)Alt+3 — Toggle comment/uncomment the current line.
Alt+3Tab / Shift+Tab — Indent / unindent the current line or selected lines.
Select lines → TabSearch
Ctrl+W — Search forward for a string.
Ctrl+W → search term → EnterAlt+W — Repeat the last search (find next).
Alt+WCtrl+W → Alt+R — Switch to regex search mode.
Ctrl+W → Alt+R → [0-9]+ → EnterCtrl+W → Alt+C — Toggle case sensitivity in search.
Ctrl+W → Alt+CCtrl+W → Alt+B — Search backwards.
Ctrl+W → Alt+B → term → EnterCtrl+\ — Search and replace. Options: Y (yes), N (no), A (all).
Ctrl+\ → http → Enter → https → Enter → ASelection (Mark)
Alt+A — Toggle mark (start/stop text selection). Move cursor to select.
Alt+A → move → Ctrl+K (cut selection)Ctrl+6 — Set mark at cursor (alternative to Alt+A).
Ctrl+6Alt+A → Ctrl+K — Select text and cut it.
Alt+A → select → Ctrl+KAlt+A → Alt+6 — Select text and copy it (without cutting).
Alt+A → select → Alt+6File Operations
Ctrl+R — Insert the contents of another file at the cursor position.
Ctrl+R → header.html → EnterCtrl+R → Ctrl+T — Open a file browser to select a file to insert.
Ctrl+R → Ctrl+TCtrl+T — Execute a command and insert its output (or invoke spell checker).
Ctrl+T → date → EnterAlt+D — Show word, line, and character count of the file (or selection).
Alt+DConfiguration (~/.nanorc)
set linenumbers — Always show line numbers.
set linenumbersset autoindent — Automatically indent new lines to match the previous line.
set autoindentset tabsize <n> — Set the displayed width of a tab character.
set tabsize 4set tabstospaces — Convert tabs to spaces when typing.
set tabstospacesset mouse — Enable mouse support.
set mouseset softwrap — Enable soft line wrapping (visual only, no newlines added).
set softwrapset backup — Always create backup files when saving.
set backup
set backupdir ~/.nano-backupsinclude /usr/share/nano/*.nanorc — Include syntax highlighting files for all supported languages.
include /usr/share/nano/*.nanorc Conclusion
nano is the right choice when you want to tweak a config file quickly or jot down a short text without having to learn an editor first: no modes, the most important shortcuts always visible in the footer, and available instantly on almost any system. Above all, remember Ctrl+O (save) and Ctrl+X (quit) – on exit nano asks about unsaved changes by itself, so you don't lose anything by accident. If you want more comfort, enable line numbers, auto-indent and syntax highlighting in your ~/.nanorc. For heavier editing or working efficiently with large files, it's worth moving up to vim later.
Further Reading
- GNU nano – official site – the project home page with the manual and all options
- nano(1) manual page – the Linux manual page for nano