LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

Nano Text Editor

Getting Started

Nano is designed to be simple and beginner-friendly. It shows the most important shortcuts at the bottom of the screen: ^ means Ctrl and M- means Alt, so ^X is Ctrl+X and M-U is Alt+U.
$ nano textfile.txt
copy
$ nano +25 textfile.txt
copy
KeyDescription
Ctrl+GDisplay help text
Ctrl+XExit nano (prompts to save if modified)
To save and quit: Ctrl+X, answer y, confirm the file name with Enter.Useful startup options:
OptionDescription
+25Open the file at line 25
-lShow line numbers
-vView mode (read-only)
-BKeep a backup of the previous version when saving

Navigation

Use the arrow keys for basic movement, or these shortcuts for faster navigation.
KeyDescription
Ctrl+AMove to beginning of line
Ctrl+EMove to end of line
Ctrl+YScroll up one page
Ctrl+VScroll down one page
Ctrl+LeftMove to previous word
Ctrl+RightMove to next word
Ctrl+_Go to a specific line (and column) number
Ctrl+CShow current cursor position (line, column)

File Operations

Nano prompts for the file name before writing, so you can also save under a new name.
KeyDescription
Ctrl+OWrite out (save) the current file
Ctrl+RRead (insert) another file into the current one
Alt+<Switch to the previous open file
Alt+>Switch to the next open file

Search and Replace

Search remembers the last term: press Enter at an empty search prompt to reuse it.
KeyDescription
Ctrl+WSearch forward
Ctrl+QSearch backward
Alt+WRepeat search, next match
Alt+QRepeat search, previous match
Ctrl+\\Search and replace
During replace, answer y to replace one match, n to skip, a to replace all.

Editing

Cut and paste work on whole lines by default. To work on a selection, set a mark first with Alt+A, then move the cursor to select.
KeyDescription
Ctrl+KCut the current line (or selected text)
Alt+6Copy the current line (or selected text)
Ctrl+UPaste the last cut text
Alt+AStart selecting text (set mark)
Alt+UUndo
Alt+ERedo
Ctrl+DDelete the character under the cursor
Ctrl+JJustify the current paragraph
Ctrl+TExecute a command (or spell check in older versions)
Alt+#Toggle line numbers
Holding Shift with the arrow keys also selects text in modern nano versions.

Configuration

Nano reads ~/.nanorc at startup. Options set there apply to every session.
$ set linenumbers
copy
$ set tabsize 4
copy
$ set tabstospaces
copy
$ set autoindent
copy
$ set mouse
copy
Copied to clipboard
Kai