cheat-sheets

nano

GNU nano is a small terminal text editor with its key bindings listed on screen. Use it for quick edits when you do not want to learn modes; see Vim for the alternative.

Documentation: nano manual, nanorc(5), Key cheatsheet

Checked against the nano 9.3 manual. In key lists ^ means Ctrl and M- means Alt (Cmd on macOS terminals that map it).

Start Options #

COMMANDDESCRIPTION
nano FILEEdit a file
nano +LINE,COLUMN FILEOpen with the cursor at a line and column
nano -l FILEShow line numbers
nano -m FILEEnable the mouse
nano -c FILEAlways show the cursor position
nano -i FILEAuto-indent new lines
nano -E FILEConvert typed tabs to spaces
nano -T N FILESet the tab size to N (default 8)
nano -S FILESoft-wrap long lines
nano -w FILEDo not hard-wrap long lines (the default)
nano -B FILEBack up the existing file to FILE~ when saving
nano -v FILEView mode (read-only)
nano -R FILERestricted mode

File and Buffers #

KEYSDESCRIPTION
^OWrite out (save)
^XClose the buffer, and exit if it is the last one; asks to save changes
^RRead a file into the buffer
^GOpen the help
^CShow the cursor position
M-XHide or show the help lines at the bottom
M-NTurn line numbers on or off
M-PShow or hide whitespace

Move and Edit #

KEYSDESCRIPTION
^A / ^EStart / end of the line
^Y / ^VPage up / down
M-GGo to a line
M-]Jump to the matching bracket
^KCut the line (or the marked region)
M-6Copy the line (or the marked region)
^UPaste
^6 or M-ASet or unset the mark to select text
Tab / Shift-TabIndent / unindent the marked region
M-3Comment or uncomment the line or region
^JJustify the paragraph or region
M-U / M-EUndo / redo

Search and Replace #

KEYSDESCRIPTION
^F or ^WSearch forward (^F and ^B forward and backward since nano 8.0)
^BSearch backward
M-F / M-BNext / previous match (per the official key cheatsheet)
M-R or ^\Replace
M-B / M-C / M-RWhile searching: toggle backwards, case-sensitive, regular expression
^T ^TSpell check

Configuration #

Settings go in ~/.nanorc (also read from $XDG_CONFIG_HOME/nano/nanorc or ~/.config/nano/nanorc), or system-wide in /etc/nanorc (the path may differ by distribution).

OPTIONDESCRIPTION
set linenumbersShow line numbers
set tabsize NTab width, greater than 0 (default 8)
set tabstospacesConvert typed tabs to spaces
set autoindentIndent new lines like the previous one
set mouseEnable the mouse
set softwrapSoft-wrap long lines
include "FILE"Read syntax definitions from a file
text
set linenumbers
set tabsize 4
set tabstospaces
set autoindent
set mouse

Version Notes #

VERSIONCHANGE
4.0No hard-wrapping by default
8.0^F and ^B became the search keys
9.0M-< and M-> became scroll left and scroll right

See Also #

Search all sheets

Tip: / or Ctrl/Cmd+K to open, Esc to close.