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

nano +<line> <file> — Open a file and jump to a specific line number.

nano +42 script.sh

nano +<line>,<col> <file> — Open a file and jump to a specific line and column.

nano +10,5 config.php

nano -B <file> — Create a backup of the file before editing (~filename~).

nano -B /etc/nginx/nginx.conf

nano -R <file> — Open a file in read-only (restricted) mode.

nano -R /etc/passwd

nano -l <file> — Show line numbers in the left margin.

nano -l script.py

nano -m <file> — Enable mouse support for clicking and scrolling.

nano -m document.txt

nano -i <file> — Enable auto-indentation.

nano -i main.go

nano -Y <syntax> <file> — Force a specific syntax highlighting language.

nano -Y php config.inc

Saving & Exiting

Ctrl+O — Write Out (save) the current file. Press Enter to confirm the filename.

Ctrl+O Enter

Ctrl+X — Exit nano. Prompts to save if there are unsaved changes.

Ctrl+X Y Enter

Ctrl+X → N — Exit without saving changes.

Ctrl+X N

Ctrl+O → new_filename → Enter — Save As: type a new filename when prompted by Write Out.

Ctrl+O backup.conf Enter

Ctrl+A / Ctrl+E — Jump to the beginning / end of the current line.

Ctrl+A

Ctrl+Y / Ctrl+V — Page Up / Page Down.

Ctrl+V

Alt+\ / 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 Enter

Alt+G — Go to line number (alternative shortcut).

Alt+G 100 Enter

Ctrl+Space / Alt+Space — Move forward / backward one word.

Ctrl+Space

Ctrl+C — Show the current cursor position (line, column, character).

Ctrl+C

Editing

Ctrl+K — Cut the current line (or selected text) to the cutbuffer.

Ctrl+K

Ctrl+U — Paste (uncut) the cutbuffer at the cursor position.

Ctrl+U

Alt+6 — Copy the current line (or selected text) without cutting it.

Alt+6

Ctrl+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+T

Ctrl+J — Justify (reflow) the current paragraph.

Ctrl+J

Alt+U — Undo the last action.

Alt+U

Alt+E — Redo the last undone action.

Alt+E

Ctrl+\ — Search and replace.

Ctrl+\ old Enter new Enter A (replace all)

Alt+3 — Toggle comment/uncomment the current line.

Alt+3

Tab / Shift+Tab — Indent / unindent the current line or selected lines.

Select lines Tab

Ctrl+W — Search forward for a string.

Ctrl+W search term Enter

Alt+W — Repeat the last search (find next).

Alt+W

Ctrl+W → Alt+R — Switch to regex search mode.

Ctrl+W Alt+R [0-9]+ → Enter

Ctrl+W → Alt+C — Toggle case sensitivity in search.

Ctrl+W Alt+C

Ctrl+W → Alt+B — Search backwards.

Ctrl+W Alt+B term Enter

Ctrl+\ — Search and replace. Options: Y (yes), N (no), A (all).

Ctrl+\ http Enter https Enter A

Selection (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+6

Alt+A → Ctrl+K — Select text and cut it.

Alt+A select Ctrl+K

Alt+A → Alt+6 — Select text and copy it (without cutting).

Alt+A select Alt+6

File Operations

Ctrl+R — Insert the contents of another file at the cursor position.

Ctrl+R header.html Enter

Ctrl+R → Ctrl+T — Open a file browser to select a file to insert.

Ctrl+R Ctrl+T

Ctrl+T — Execute a command and insert its output (or invoke spell checker).

Ctrl+T date Enter

Alt+D — Show word, line, and character count of the file (or selection).

Alt+D

Configuration (~/.nanorc)

set linenumbers — Always show line numbers.

set linenumbers

set autoindent — Automatically indent new lines to match the previous line.

set autoindent

set tabsize <n> — Set the displayed width of a tab character.

set tabsize 4

set tabstospaces — Convert tabs to spaces when typing.

set tabstospaces

set mouse — Enable mouse support.

set mouse

set softwrap — Enable soft line wrapping (visual only, no newlines added).

set softwrap

set backup — Always create backup files when saving.

set backup
set backupdir ~/.nano-backups

include /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

  • vim – powerful modal editor for advanced editing
  • less – pager for viewing files without editing them
  • mc – terminal file manager with the built-in editor mcedit