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.
means Ctrl+X, and case does not matter. These keys are the reason most people open this page.
Key
Action
Write the file out, then Enter to accept the filename
Save with no filename prompt
Exit; asks first if anything changed
then Enter
Answer "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 name
Save a copy under another filename
at the prompt
Back up the old version as first
at the prompt
Write DOS line endings ( for old Mac)
/ at the prompt
Append or prepend to the existing file
Shortcut Notation
The two lines at the bottom of the screen use the same notation as this page.
Notation
What 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 key
Insert 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.
Key
Action
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
Key
Action
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.
Key
Action
or
Set the mark at the cursor (press again to drop it)
Shift+arrows
Select 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+Tab
Indent or unindent the marked lines ( and also work)
Comment or uncomment the marked lines
with a mark set
Search and replace inside the selection only
Search
Key
Action
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 prompt
Repeat the last search
at the prompt
Toggle case sensitivity
at the prompt
Treat the term as a regular expression
at the prompt
Switch over to replace
/ at the prompt
Step 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
Key
Action
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 prompt
Turn on regular expressions, so or works
at the search prompt
Make the match case sensitive
in the replacement
Back-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
Key
Action
Undo the last change ( then if Alt is not sending Meta)
Redo
repeatedly
Walk 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
Key
Action
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 setting
Action
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
Key
Action
Insert another file at the cursor
at the prompt
Open it as a separate buffer instead of pasting it in
at the prompt
Run a command and insert its output
at the or prompt
Open the file browser and pick a path
Open several files at once; and switch between them
then a new name
Save the buffer as a different file
at the prompt
Keep the previous version as
Command Line Options
Command
What 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 .
Setting
What 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.
Ctrl+6, or Ctrl+Shift+6 on a Mac keyboard; is the alternative
Forward delete
fn+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
Task
nano
Vim
Starting to type
Just type
Press first
Save and exit
then , or
Quit without saving
then
Undo
Search
Finding the keys
Printed at the bottom of the screen
, or run
Where it is installed
Debian, Ubuntu, most cloud images
Practically everywhere, including minimal images
Suits
A quick config edit over SSH
Long 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.