Cheat Sheet

nano Editor Cheat Sheet

nano is the editor that opens when you type nano file.conf over SSH, and on Debian and Ubuntu it is what crontab -e, visudo, and git hand you by default. This sheet covers the shortcuts people look up: saving and exiting, cut and paste, search and replace, undo, and the nanorc settings worth turning on.

Last updated September 11, 2026

Save and Exit

means Ctrl+X, and case does not matter. These keys are the reason most people open this page.

KeyAction
Write the file out, then Enter to accept the filename
Save with no filename prompt
Exit; asks first if anything changed
then EnterAnswer "Save modified buffer?" and keep the name
Exit and throw the changes away
Cancel a prompt and go back to editing
Save and leave in one go
then a new nameSave a copy under another filename
at the promptBack up the old version as first
at the promptWrite DOS line endings ( for old Mac)
/ at the promptAppend or prepend to the existing file

Shortcut Notation

The two lines at the bottom of the screen use the same notation as this page.

NotationWhat to press
Hold Ctrl, press O. No Shift needed, the capital is just how nano prints it
Meta: Alt+U on Linux and Windows, Option+U on a Mac once Option is set as Meta
then The same as . Press Esc, release, then the key. Works in every terminal
Ctrl+6, which on many keyboards means Ctrl+Shift+6; does the same job
then a keyInsert a control code instead of running it
The built-in help, listing every binding your version has
Hide or show the two help lines at the bottom

Cut, Copy and Paste

nano keeps its own cutbuffer. It is not the system clipboard, and over SSH it lives on the server.

KeyAction
Cut the current line into the cutbuffer
Cut consecutive lines into one buffer, pasted back together
Paste the cutbuffer
Copy the current line, or the marked region, leaving it in place
, move, Mark a region, then cut it
Cut from the cursor to the end of the file
Toggle: make cut to end of line instead of the whole line
Paste is a terminal paste; use this only to insert a literal control code

Delete

KeyAction
Delete the current line, leaving the cutbuffer alone
Delete the line but keep it, so can put it back
Backspace or Delete the character before the cursor
Delete or Delete the character under the cursor
Delete the word to the left
Delete the word to the right
then Empty the file: go to the top, cut to the end
Undo it when that was the wrong line

Select Text

nano calls a selection the mark.

KeyAction
or Set the mark at the cursor (press again to drop it)
Shift+arrowsSelect without the mark, if your terminal passes them through
Select all: top of the file, mark, end of the file
/ Cut or copy the marked region
Tab / Shift+TabIndent or unindent the marked lines ( and also work)
Comment or uncomment the marked lines
with a mark setSearch and replace inside the selection only
KeyAction
Search forward (Where Is); Enter runs it, cancels
The same forward search, added in nano 8.0
or Search backwards
or Find the next match
or Find the previous match
Enter on an empty promptRepeat the last search
at the promptToggle case sensitivity
at the promptTreat the term as a regular expression
at the promptSwitch over to replace
/ at the promptStep back and forward through past searches

Searches wrap around the end of the file, and the status bar says so when they do.

Search and Replace

KeyAction
or Open replace: it asks for the text, then the replacement
/ Replace this match, or skip it
Replace every remaining match
Stop where you are
at the search promptTurn on regular expressions, so or works
at the search promptMake the match case sensitive
in the replacementBack-reference to the first group, with regex on

The pattern syntax is the POSIX set, the same one grep uses. For the same edit across many files, sed is faster than opening each one.

Undo and Redo

KeyAction
Undo the last change ( then if Alt is not sending Meta)
Redo
repeatedlyWalk back to the start of the session

Undo is on by default in current nano; builds older than 4.0 needed in the nanorc. The history is per open file and goes away when you exit, so undo cannot rescue a file you already saved and closed. keeps the previous version for that.

Move Around

KeyAction
or Go to a line: type , or for line and column
Open with the cursor already on line 42
/ Top of the file / end of the file
/ Start of line / end of line
/ Page up / page down
/ One word left / right
/ Previous / next block of text
Jump to the matching bracket
Center the current line and redraw a messed-up screen
Report the current line, column, and character
Count lines, words, and characters
/ Previous / next open file ( and too)

and switched to horizontal scrolling in nano 9.0. Use and to move between buffers.

Line Numbers

Key or settingAction
Turn line numbers on or off
Start with line numbers showing
Turn them on permanently in
Report the line and column without turning anything on
()Keep the position in the status bar at all times
Show tabs and spaces, which is what you want in YAML and Makefiles

Insert and Save Files

KeyAction
Insert another file at the cursor
at the promptOpen it as a separate buffer instead of pasting it in
at the promptRun a command and insert its output
at the or promptOpen the file browser and pick a path
Open several files at once; and switch between them
then a new nameSave the buffer as a different file
at the promptKeep the previous version as

Command Line Options

CommandWhat it does
Show line numbers
Start on line 42 ( for a column too)
Start at the first match instead of a line number
No hard wrapping, so a long config line stays one line
Soft-wrap long lines on screen without changing the file
Tabs four columns wide, typed as spaces
Keep the previous line's indentation on Enter
Mouse support: click to move, drag to select
Back up the previous version as
Show the cursor position all the time
View only, no editing
Reopen at the position you left the cursor last time
cuts to end of line instead of the whole line
Force a syntax highlighting definition
Edit a root-owned file ( is the safer habit)

nanorc Config

Your settings go in , the machine-wide ones in .

SettingWhat it does
Line numbers every time
A tab is four columns
Typing a tab inserts spaces
Keep the previous line's indentation
Line and column always in the status bar
Wrap long lines on screen only
Click to move the cursor
Remember searches between sessions
Reopen files where you left off
Keep the old version as ( to park them elsewhere)
Syntax highlighting for every language shipped
Make plain suspend nano again
Recolor the interface (, too)

A starter file:

set linenumbers
set constantshow
set tabsize 4
set tabstospaces
set softwrap
set historylog
set positionlog
set backup
include /usr/share/nano/*.nanorc

Settings take effect the next time nano starts. A syntax error in the file stops nano at launch with the offending line number, so check it before you rely on the machine.

Default Editor

What opens for , , and is set outside nano.

CommandWhat it does
In or , with beside it
Commit messages and interactive rebase (git cheat sheet)
Debian and Ubuntu: pick nano system-wide
Set it for this one command
sudo clears the environment, so pass it on the line
What opens

Mac Keyboard

Ctrl shortcuts work as printed. Only the Meta (Alt) ones need setting up.

WhereWhat to do
Terminal.appSettings > Profiles > Keyboard > "Use Option as Meta Key"
iTerm2Settings > Profiles > Keys > Left Option key > Esc+
Any terminal, no setupPress Esc, release, then the letter: undoes
Ctrl+6, or Ctrl+Shift+6 on a Mac keyboard; is the alternative
Forward deletefn+Delete; the Delete key on its own is backspace
Local on recent macOS is a symlink to pico, with no undo and no line numbers. for GNU nano

Over SSH you are running the server's nano, so the pico substitution never bites you there. The Option key setting does.

nano vs Vim

TasknanoVim
Starting to typeJust typePress first
Save and exit then , or
Quit without saving then
Undo
Search
Finding the keysPrinted at the bottom of the screen, or run
Where it is installedDebian, Ubuntu, most cloud imagesPractically everywhere, including minimal images
SuitsA quick config edit over SSHLong sessions, big files, macros

Learning both pays off, because the box that has one often lacks the other. The Vim cheat sheet covers the other half.

Gotchas

  • leaves straight away when nothing changed. If it asks "Save modified buffer?", something did change, even if it was one stray keystroke. saves, discards, goes back.
  • The cutbuffer is not your system clipboard. on the server then Cmd+V on your laptop pastes whatever the laptop had, not the line you cut.
  • Pasted YAML or Python that comes out stair-stepped means auto-indent is on. turns it off, then paste again.
  • Editing a root-owned file without only fails at the end, when the write is refused. Save elsewhere with and move it, or reopen with .
  • saves in current nano. If the terminal freezes instead, it took as flow control: press to unfreeze. hands both keys back to the terminal on purpose.
  • does not suspend by default. It prints a hint pointing at , which does; brings nano back. in your nanorc restores the shell habit.
  • on a config file is still worth typing. Hard wrapping is off by default now, but on an older box can have it on, and a wrapped line in nginx or sshd config breaks the service.

nano FAQ

How do I save and exit nano?

Press Ctrl+O to write the file, Enter to accept the filename it offers, then Ctrl+X to leave. Ctrl+S saves without the filename prompt, so Ctrl+S then Ctrl+X does the whole job. If you press Ctrl+X with unsaved changes, nano asks "Save modified buffer?": Y then Enter saves, N quits and throws the changes away, and Ctrl+C cancels and puts you back in the file. One catch on server configs: if you opened a root-owned file without sudo, nothing fails until the write, and then it says Permission denied. Save a copy somewhere you can write (Ctrl+O, then type /tmp/myfile) and move it with sudo, or quit and reopen with sudoedit.

How do I copy and paste in nano?

Ctrl+K cuts the current line and Ctrl+U pastes it back; press Ctrl+K several times in a row and the lines pile into one buffer that Ctrl+U pastes together. To copy without removing, use Alt+6. To work on a block, set the mark with Ctrl+6 (or Alt+A), move to the other end, then Ctrl+K to cut it or Alt+6 to copy it. That cutbuffer belongs to nano and is not your system clipboard, which matters over SSH: text you cut in nano lives on the server. To get it onto your own machine, select it with the mouse in your terminal instead (hold Shift if nano has mouse mode on). Pasting the other way is a normal terminal paste, but if the result comes out stair-stepped, auto-indent is on: press Alt+I to turn it off and paste again.

How do I select all text in nano and delete it?

Alt+\ goes to the top of the file, Ctrl+6 sets the mark, Alt+/ goes to the end, and Ctrl+K cuts everything in between (Alt+6 copies it instead). If you only want the file empty, skip the marking: Alt+\ to the top, then Alt+T cuts from the cursor to the end of the buffer in one keystroke. For a single line, Alt+Del deletes it without disturbing the cutbuffer. Alt+U undoes any of it if you cut more than you meant to, and nothing touches the file on disk until you save.

Why do the Alt (M-) shortcuts not work in nano on a Mac?

macOS terminals do not send Option as Meta by default. In Terminal.app turn on Settings > Profiles > Keyboard > "Use Option as Meta Key"; in iTerm2 set Profiles > Keys > Left Option key to Esc+. You can also skip the setting entirely: press Esc, release it, then the letter, so Esc U is Alt+U (undo) and Esc G is Alt+G (go to line). Ctrl shortcuts need no setup. One more Mac quirk, for local files only: /usr/bin/nano on recent macOS is a symlink to pico (UW PICO 5.09), not GNU nano, so undo and line numbers are missing. Run brew install nano if you want the real thing locally. Over SSH you are using the server's nano, so only the Option key setting matters.

How do I make nano the default editor?

Add export EDITOR=nano and export VISUAL=nano to ~/.bashrc or ~/.zshrc for anything that reads the environment. Git has its own setting: git config --global core.editor nano. On Debian and Ubuntu, sudo update-alternatives --config editor sets the system-wide choice that visudo and crontab -e follow. For one command, put it on the line: EDITOR=nano visudo. Note that sudo clears the environment, so sudo crontab -e uses root's editor, not yours; sudo EDITOR=nano crontab -e fixes that. kubectl reads KUBE_EDITOR.

Related cheat sheets