File handling 6
nano's help lines and manual write ^ for Ctrl and M- for Meta, which is normally the Alt key, so ^X is Ctrl + X and M-U is Alt + U.
When a terminal does not pass Ctrl or Alt chords, Esc stands in: press Esc twice and then the key for a Ctrl chord, or Esc once and then the key for an Alt chord.
| Action | Shortcut |
|---|---|
| Save fileWrites the buffer under its current name without showing a prompt. | Ctrl+S |
| Save asOpens the Write-Out prompt, which asks for a file name; with a marked region, only that region is written. | Ctrl+O |
| Insert fileOpens the Read-File prompt; the named file is added at the cursor of the buffer being edited. | Ctrl+R |
| Insert fileThe Insert key opens the same Read-File prompt. | Insert |
| Close buffer and exitLeaves nano when the closed buffer was the last one; changed text brings up a save question first unless --saveonexit is set. | Ctrl+X |
| Discard bufferCloses the buffer without saving its changes; nano ends with exit status 2 if no other buffer is open. | Ctrl+OthenCtrl+QorCtrl+XthenCtrl+Q |
Editing 11
On some terminals, holding Shift while pressing the cursor keys selects text as well; adding Ctrl or Alt makes each step longer.
| Action | Shortcut |
|---|---|
| Cut lineRepeated presses collect consecutive lines in the cutbuffer; with the mark set, the whole selection is cut. | Ctrl+K |
| Copy lineStores the line, or the marked region, in the cutbuffer and leaves the text in place. | Alt+6 |
| Paste from cutbufferInserts everything cut or copied so far at the cursor position. | Ctrl+U |
| Complete wordFinishes the fragment before the cursor with a word found elsewhere in the buffer, when one matches. | Ctrl+] |
| Toggle commentActs on the current line or all marked lines, using the comment style of the active syntax. | Alt+3 |
| Undo last actionReverses the most recent text change, such as added or deleted text. | Alt+U |
| Redo undone actionReapplies the change that the last undo took away. | Alt+E |
| Toggle the markStarts a selection at the cursor; move the cursor to extend it, and cutting or copying switches the mark off. | Alt+A |
| Toggle the markThe highlighted text runs from the marked spot to wherever the cursor is moved. | Ctrl+6 |
| Indent lineShifts the current line, or all marked lines, to the right; no selection is required. | Alt+} |
| Unindent lineShifts the current line, or all marked lines, back to the left. | Alt+{ |
Deletion 6
| Action | Shortcut |
|---|---|
| Delete character leftThe Backspace key runs the same function. | Ctrl+H |
| Delete character at cursorThe Delete key runs the same function. | Ctrl+D |
| Delete word leftErases everything between the cursor and the start of the word before it. | Alt+Backspace |
| Delete word leftThe binding the manual gives for the chopwordleft function. | Ctrl+Shift+Delete |
| Delete word rightErases from the cursor up to where the next word starts. | Ctrl+Delete |
| Delete current lineThrows the line, or the marked region, away instead of cutting it. | Alt+Delete |
Search and replace 10
Ctrl + F and Ctrl + B start searches since nano 8.0, with Alt + F and Alt + B repeating them; on older versions search with Ctrl + W.
| Action | Shortcut |
|---|---|
| Search forwardOpens the search prompt; by default a search ignores case and treats the text as a literal string. | Ctrl+F |
| Search backwardOpens the search prompt with the direction set toward the start of the buffer. | Ctrl+B |
| Find next occurrenceJumps to the following match of the current search string. | Alt+F |
| Find previous occurrenceJumps to the nearest match before the cursor. | Alt+B |
| Start replacingAsks at every match whether to replace it; with a marked region, only matches inside it are considered. | Alt+R |
| Search forwardSecond default key for the search prompt, next to Ctrl + F. | Ctrl+W |
| Search backwardNot bound when nano runs with --preserve, which keeps the key for terminal flow control. | Ctrl+Q |
| Find next occurrenceSecond default key for repeating the search forward. | Alt+W |
| Find previous occurrenceSecond default key for repeating the search backward. | Alt+Q |
| Start replacingOpens the same replace prompt as Alt + R. | Ctrl+\ |
Search prompt keys 9
| Action | Shortcut |
|---|---|
| Toggle case sensitivityPressed at the search or replace prompt, makes the search respect upper and lower case, or ignore it again. | Alt+C |
| Toggle regular expressionsAt the prompt, switches between literal text and a regular expression, which always matches within one line. | Alt+R |
| Reverse search directionAt the prompt, flips the search between forward and backward. | Alt+B |
| Switch search to replaceTurns the search prompt into the replace prompt, and back. | Ctrl+R |
| Go to first lineFrom the search or go-to-line prompt, jumps straight to the top of the file. | Ctrl+Y |
| Go to last lineFrom the search or go-to-line prompt, jumps straight to the bottom of the file. | Ctrl+V |
| Recall earlier entriesSteps through earlier search and replacement strings, which nano stores when --historylog is on. | UporDown |
| Complete from historyType the first characters of an earlier search string, then press it to cycle through the ones that match. | Tab |
| Cancel promptLeaves any prompt or yes-no question without carrying out the command. | Ctrl+C |
Read and write prompt keys 9
| Action | Shortcut |
|---|---|
| Open file browserAvailable at the Read-File and Write-Out prompts; lets a file be picked from a directory listing. | Ctrl+T |
| Toggle DOS formatAt the Write-Out prompt, saves the file with CR+LF line endings. | Alt+D |
| Toggle appendingAt the Write-Out prompt, adds the text to the end of the named file instead of overwriting it. | Alt+A |
| Toggle prependingAt the Write-Out prompt, writes the text at the beginning of the named file. | Alt+P |
| Toggle backup fileAt the Write-Out prompt, keeps the previous version under the same name with a tilde added. | Alt+B |
| Switch to command executionAt the Read-File prompt, changes from naming a file to typing a command whose output is inserted. | Ctrl+X |
| Toggle new bufferAt the Read-File or Execute prompt, puts the result in a new empty buffer rather than the current one. | Alt+F |
| Toggle DOS conversionAt the Read-File prompt, reads the file without converting it from DOS format; converting is the default. | Alt+N |
| Pipe buffer to commandAt the Execute prompt, sends the buffer or marked region to the command as its input. | Alt+\ |
Operations 13
| Action | Shortcut |
|---|---|
| Execute a commandPrompts for a program to run and inserts its output into the buffer. | Ctrl+T |
| Spell checkRuns hunspell or GNU spell by default, or the program set with --speller. | Ctrl+TthenCtrl+S |
| Syntax checkRuns the linter that the active syntax defines and lets you step through its messages. | Ctrl+TthenCtrl+Y |
| Run formatterPasses the whole buffer through the formatting program that the active syntax defines. | Ctrl+TthenCtrl+O |
| Suspend nanoReturns control to the shell until the process is resumed with fg. | Ctrl+TthenCtrl+Z |
| Indent marked regionWith lines marked, shifts them all one step right; without a mark it inserts a tab. | Tab |
| Unindent marked regionShifts the marked lines back to the left. | Shift+Tab |
| Justify paragraphRewraps the current paragraph, or the marked region, to the fill width. | Ctrl+J |
| Justify entire bufferRewraps every paragraph of the buffer in one step. | Alt+J |
| Cut to end of bufferMoves everything from the cursor to the last line into the cutbuffer. | Alt+T |
| Verbatim inputInserts the next key literally, such as a control code; hexadecimal digits typed after it enter a Unicode character. | Alt+V |
| Record macroPress once to start storing keystrokes and again to stop; pressing it twice in a row keeps the old macro. | Alt+: |
| Replay macroPlays back the keystrokes of the last recorded macro. | Alt+; |
Moving around 28
| Action | Shortcut |
|---|---|
| Back one character | Left |
| Forward one character | Right |
| Back one wordLands on the first letter of the previous word. | Ctrl+Left |
| Forward one wordStops at the start of the next word, or at word ends with --afterends. | Ctrl+Right |
| Back one word | Alt+Space |
| Forward one word | Ctrl+Space |
| Go to start of line | Ctrl+A |
| Go to end of line | Ctrl+E |
| Go to start of lineWith --smarthome, it first goes to where the non-whitespace text of the line begins. | Home |
| Go to end of line | End |
| Up one line | Ctrl+P |
| Down one line | Ctrl+N |
| Previous blockBlocks are stretches of text separated by one or more blank lines. | Ctrl+Up |
| Next blockGoes to the first line of the following block of text. | Ctrl+Down |
| Previous block | Alt+7 |
| Next block | Alt+8 |
| Start of paragraphGoes to where the paragraph begins; pressed again, to the beginning of the one before. | Alt+(orAlt+9 |
| End of paragraphGoes just past the paragraph's last line; pressed again, past the following paragraph. | Alt+)orAlt+0 |
| First row of the view | Alt+Home |
| Last row of the view | Alt+End |
| Up one page | Ctrl+Y |
| Down one page | Ctrl+V |
| Up one page | Page Up |
| Down one page | Page Down |
| Go to first line | Alt+\ |
| Go to last line | Alt+/ |
| Go to first line | Ctrl+Home |
| Go to last line | Ctrl+End |
Special movement 11
| Action | Shortcut |
|---|---|
| Go to lineAsks for a line and optional column; negative numbers count from the end of the buffer. | Alt+G |
| Go to lineOpens the same line and column prompt as Alt + G. | Ctrl+_ |
| Go to matching bracketWorks when the cursor is on a bracket, brace or parenthesis and jumps to its partner. | Alt+] |
| Scroll view leftShifts the visible text by one tab size; assigned to this key since version 9.0. | Alt+< |
| Scroll view rightShifts the visible text one tab size; the cursor moves to a longer line when needed to stay visible. | Alt+> |
| Scroll view upSlides the view by one row while the cursor keeps its place in the text where possible. | Alt+Up |
| Scroll view downShows one more row at the bottom; the cursor stays on its text position if it can. | Alt+Down |
| Scroll view upScrolls one row just as Alt + Up does. | Alt+- |
| Scroll view downScrolls one row just as Alt + Down does. | Alt+= |
| Center cursor lineScrolls so that the line with the cursor sits in the middle of the view. | Ctrl+L |
| Cycle cursor line positionPuts the cursor line in the middle of the view, then at the top, then at the bottom on repeated presses. | Alt+% |
Anchors and buffers 9
| Action | Shortcut |
|---|---|
| Place or remove anchorAn anchor works as a bookmark on a line and shows in the margin when line numbers are on. | Alt+Insert |
| Previous anchorJumps to the nearest anchor above the cursor and wraps around at the top of the buffer. | Alt+Page Up |
| Next anchorJumps to the nearest anchor below the cursor and wraps around at the bottom. | Alt+Page Down |
| Place or remove anchor | Alt+" |
| Next anchor | Alt+' |
| Previous bufferShows the buffer that comes before the current one when several files are open. | Alt+Left |
| Next bufferShows the buffer that comes after the current one when several files are open. | Alt+Right |
| Previous buffer | Alt+, |
| Next buffer | Alt+. |
Information 3
| Action | Shortcut |
|---|---|
| Report cursor positionShows the line, column and character position of the cursor on the status bar. | Ctrl+C |
| Count lines, words, charactersReports the totals on the status bar, for the whole buffer or just the marked region. | Alt+D |
| Display helpInside the help viewer, Ctrl + Y and Ctrl + V page through the text and Ctrl + X closes it. | Ctrl+G |
Toggles 13
| Action | Shortcut |
|---|---|
| Constant position displayKeeps line, column and character numbers on the status bar; same as starting with -c. | Alt+C |
| Line numbersShows or hides the numbers left of the text; same as starting with -l. | Alt+N |
| Whitespace displayShows tabs and spaces as visible characters, or hides them again. | Alt+P |
| Soft wrappingDisplays overlong lines on several screen rows without changing the file; same as -S. | Alt+S |
| Help linesRemoves or restores the two key-list lines at the bottom; works in every menu except the help viewer and linter. | Alt+X |
| Title and status barsAffects the title bar and status bar only; the help lines stay as they are. | Alt+Z |
| Smart Home keyWhen on, Home first jumps to where the non-blank text of the line starts. | Alt+H |
| Auto indentA new line starts with the same leading tabs and spaces as the line before it. | Alt+I |
| Cut from cursorMakes Ctrl + K cut from the cursor to the end of the line rather than the whole line. | Alt+K |
| Long-line hard wrappingBreaks a line onto the next one as soon as it grows past the fill width. | Alt+L |
| Mouse supportWith the mouse on, a click places the cursor and a second click in the same spot toggles the mark. | Alt+M |
| Tabs to spacesEach typed tab becomes the matching number of spaces; pasted tabs stay as they are. | Alt+O |
| Syntax coloringHas an effect only when the nanorc file defines syntaxes. | Alt+Y |
File browser and help viewer 8
| Action | Shortcut |
|---|---|
| Search file namesIn the file browser, looks for a file name that contains the typed string. | Ctrl+WorW |
| Go to directoryIn the file browser, asks for a directory and lists it, anywhere in the filesystem. | Ctrl+_orG |
| Open selected itemOn a directory, shows what it contains; on a file, hands its path back to the prompt and closes the browser. | EnterorS |
| Go to first fileIn the file browser, selects the first entry of the list. | Home |
| Go to last fileIn the file browser, selects the final entry of the list. | End |
| Next pageWorks as a paging key in the file browser and the help viewer only. | Space |
| Previous pagePages backward in the file browser and the help viewer. | Backspace |
| Close browser or help viewerLeaves the file browser or the help text; Ctrl + X does the same there. | Ctrl+C |
Function keys 12
| Action | Shortcut |
|---|---|
| Display helpOpens the same help text as Ctrl + G; inside the viewer it closes it again. | F1 |
| Close buffer and exitRuns the same function as Ctrl + X. | F2 |
| Save asRuns the same function as Ctrl + O. | F3 |
| Justify paragraphRuns the same function as Ctrl + J. | F4 |
| Insert fileRuns the same function as Ctrl + R. | F5 |
| Search forwardRuns the same function as Ctrl + F. | F6 |
| Up one pageRuns the same function as Ctrl + Y. | F7 |
| Down one pageRuns the same function as Ctrl + V. | F8 |
| Cut lineRuns the same function as Ctrl + K. | F9 |
| Paste from cutbufferRuns the same function as Ctrl + U. | F10 |
| Report cursor positionRuns the same function as Ctrl + C. | F11 |
| Spell checkStarts the spell checker directly, without the Execute prompt. | F12 |
Command-line options 24
| Action | Shortcut |
|---|---|
| Open a fileWithout a file name nano opens an empty buffer; several names can be given to edit files in a row. | nano FILE |
| Open at a lineAdd a comma and a column number to set the column too; negative numbers count from the end. | nano +LINE FILE |
| Open at first matchUse +? for the last occurrence; c or r after the plus sign makes the search case sensitive or a regular expression. | nano +/STRING FILE |
| Read standard inputLets the output of another command be piped into a buffer for editing. | nano - |
| Show line numbersNumbers appear left of the text; a line with an anchor also gets a mark in that margin. | -l / --linenumbers |
| Enable mouse supportClicks place the cursor, two clicks set the mark, and clicking a shortcut in the help lines runs it. | -m / --mouse |
| Indent new lines automaticallyA new line copies the leading tabs and spaces of the previous one. | -i / --autoindent |
| Convert typed tabs to spacesOnly typed tabs are converted; tabs in pasted text are left alone. | -E / --tabstospaces |
| Set tab widthThe long form is --tabsize=NUMBER; the default width is 8 columns. | -T NUMBER |
| Soft-wrap long linesAdd --atblanks to wrap at whitespace rather than at the screen edge. | -S / --softwrap |
| Keep a backup copyOn saving, the previous version is kept under the same name with a tilde added. | -B / --backup |
| Open read-onlyThe file contents cannot be changed; other files may still be opened for viewing. | -v / --view |
| Always show cursor positionLine, column and character numbers stay on the status bar; this overrides --quickblank. | -c / --constantshow |
| Hide the help linesCalled Expert mode: the two shortcut lines at the bottom are left out, moving the status bar down. | -x / --nohelp |
| Choose syntax highlightingThe long form is --syntax=NAME; -z prints the names of the available syntaxes. | -Y NAME |
| Remember cursor positionReopening one of the 200 files edited most recently puts the cursor back where it was; anchors return too. | -P / --positionlog |
| Save search historyKeeps the last hundred search strings, replacement strings and executed commands for later sessions. | -H / --historylog |
| Save on exit without askingCtrl + X then writes a changed buffer straight away, handy when nano composes mail for another program. | -t / --saveonexit |
| Skip nanorc filesStarts with built-in defaults by reading neither the system's nor the user's nanorc. | -I / --ignorercfiles |
| Restricted modeLimits reading and writing to the files named on the command line; no history, suspending, spell checking or shell commands. | -R / --restricted |
| Keep terminal flow controlLeaves the XOFF and XON keys to the terminal, so Ctrl + S no longer saves. | -p / --preserve |
| Use modern key bindingsRemaps the editor so Ctrl + X cuts, Ctrl + C copies, Ctrl + V pastes, Ctrl + Z undoes and Ctrl + Q quits. | --modernbindings |
| Show versionPrints the version number and exits without opening the editor. | -V / --version |
| List command-line optionsPrints a summary of the options and exits. | -h / --help |
No row on this page matches that filter.
Notes
Save, exit, and the prompt that confuses everyone
Ctrl + S saves in place and Ctrl + X exits, offering to save if the buffer changed — answer Y, then confirm the file name with Enter. Ctrl + O is "write out", the older save-as flow that prompts for a name each time. If you are stuck at a prompt, Ctrl + C cancels it; in the main editor the same key reports the cursor position instead. Ctrl + G opens the help screen, which lists every binding for the installed version.
Cut, copy and paste are lines, not selections
Ctrl + K cuts the current line into the cut buffer and Ctrl + U pastes it; pressing Ctrl + K on consecutive lines accumulates them, so cut-five-lines-and-move-them is five presses and one paste. Alt + 6 copies a line without removing it. To act on a region instead of whole lines, set a mark with Alt + A, move the cursor to extend the selection, then cut or copy. Alt + U undoes and Alt + E redoes.
Moving and searching
Ctrl + A and Ctrl + E go to line start and end, Ctrl + Left and Ctrl + Right move by word, and Ctrl + Y and Ctrl + V page up and down — a layout nano keeps from Pico, the editor it was written to emulate. Alt + G goes to a line number and Alt + \ and Alt + / jump to the top and bottom of the file. Ctrl + F searches forward since nano 8.0 (Ctrl + W, the older key, still works), and Alt + R opens search-and-replace with a confirmation for each match.
Useful toggles
Alt + N shows line numbers, Alt + S soft-wraps long lines so they are readable without horizontal scrolling, and Alt + P shows whitespace, which is how you find the tab-versus-spaces problem in a YAML file. Alt + 3 comments or uncomments the current line using the comment style of the active syntax. Line numbers and soft wrapping can be made permanent with set linenumbers and set softwrap in ~/.nanorc.
Questions
What do ^ and M- mean at the bottom of the screen?
^ is Ctrl and M- is Alt (Meta). ^X means Ctrl + X; M-U means Alt + U. If a chord does not get through, press Esc twice and then the key for Ctrl, or Esc once and then the key for Alt.
How do I select text in nano?
Press Alt + A to set a mark, move the cursor to extend the selection, then Ctrl + K to cut or Alt + 6 to copy it.
Why does Ctrl + S not save on my server?
nano has saved with Ctrl + S since version 2.9.0. On older versions use Ctrl + O then Enter. The key is also left to the terminal as flow control (XOFF) when nano is started with -p (--preserve).
How do I go to a specific line?
Alt + G, then type the line number and press Enter. You can also start nano with +N filename to open at line N.
Sources and checks
- GNU nano 9.2 — Overview of nano's shortcuts (the official cheat sheet) Main list of editor keys, printed as Ctrl+S, Alt+U
- The GNU nano text editor — manual for version 9.2 Key notation, feature toggles, anchors, file browser, command-line options
- GNU nano 9.2 source code — src/global.c (table of default key bindings) at release tag v9.2 Second default keys, function keys and prompt keys that the cheat sheet does not print
- GNU nano NEWS file at release tag v9.2 Versions in which default keys changed
Every row on this page was matched to a line in the documentation above on . A binding that could not be found there is not listed.
Found a wrong or missing key? Tell us and it gets checked against the source. How we verify describes the process and its limits.