The GNU nano text editor

This manual documents GNU nano, version 7.2.


1 Introduction

GNU nano is a small and friendly text editor. Besides basic text editing, nano offers features like undo/redo, syntax coloring, interactive search-and-replace, auto-indentation, line numbers, word completion, file locking, backup files, and internationalization support.

The original goal for nano was to be a complete bug-for-bug emulation of Pico. But currently the goal is to be as compatible as is reasonable while offering a superset of Pico’s functionality. See Pico Compatibility for more details on how nano and Pico differ.

Starting with version 4.0, nano no longer hard-wraps an overlong line by default. It further uses linewise scrolling by default, and by default includes the line below the title bar into the editing area. If you want the old, Pico behavior back, you can use the following options: --breaklonglines, --jumpyscrolling, and --emptyline (or -bje).

Please report bugs via https://savannah.gnu.org/bugs/?group=nano.

For background information see https://nano-editor.org/.


2 Invoking

The usual way to invoke nano is:

nano [FILE]

But it is also possible to specify one or more options (see Command-line Options), and to edit several files in a row. Additionally, the cursor can be put on a specific line of a file by adding the line number with a plus sign before the filename, and even in a specific column by adding it with a comma. (Negative numbers count from the end of the file or line.) The cursor can also be put on the first or last occurrence of a specific string by specifying that string after +/ or +? before the filename. The string can be made case sensitive and/or caused to be interpreted as a regular expression by inserting a c and/or r after the plus sign. These search modes can be explicitly disabled by using the uppercase variant of those letters: C and/or R. When the string contains spaces, it needs to be enclosed in quotes. A more complete command synopsis thus is:

nano [OPTION]… [[+LINE[,COLUMN]|+[crCR](/|?)STRING] FILE]…

Normally, however, you set your preferred options in a nanorc file (see Nanorc Files). And when using set positionlog (making nano remember the cursor position when you close a file), you will rarely need to specify a line number.

As a special case: when instead of a filename a dash is given, nano will read data from standard input. This means you can pipe the output of a command straight into a buffer, and then edit it.


3 Editor Basics


3.1 Screen Layout

The default screen of nano consists of four areas. From top to bottom these are: the title bar, the edit window, the status bar, and two help lines.

The title bar consists of three sections: left, center and right. The section on the left displays the version of nano being used. The center section displays the current filename, or "New Buffer" if the file has not yet been named. The section on the right displays "Modified" if the file has been modified since it was last saved or opened.

The status bar is the third line from the bottom of the screen. It shows important and informational messages. Any error messages that occur from using the editor will appear on the status bar. Any questions that are asked of the user will be asked on the status bar, and any user input (search strings, filenames, etc.) will be input on the status bar.

The two help lines at the bottom of the screen show some of the most essential functions of the editor.


3.2 Entering Text

nano is a "modeless" editor. This means that all keystrokes, with the exception of Control and Meta sequences, enter text into the file being edited.

Characters not present on the keyboard can be entered in two ways:

For example, typing Esc Esc 2 3 4 will enter the character "ê" — useful when writing about a French party. Typing M-V 0 0 2 2 c 4 will enter the symbol "⋄", a little diamond.

Typing M-V followed by anything other than a hexadecimal digit will enter this keystroke verbatim into the buffer, allowing the user to insert literal control codes (except ^J) or escape sequences.


3.3 Commands

Commands are given by using the Control key (Ctrl, shown as ^) or the Meta key (Alt or Cmd, shown as M-).

If for some reason on your system the combinations with Ctrl or Alt do not work, you can generate them by using the Esc key. A control-key sequence is generated by pressing the Esc key twice and then pressing the desired key, and a meta-key sequence by pressing the Esc key once and then pressing the desired key.


3.4 The Cutbuffer

Text can be cut from a file a whole line at a time with ^K. The cut line is stored in the cutbuffer. Consecutive strokes of ^K will add each cut line to this buffer, but a ^K after any other keystroke will overwrite the entire cutbuffer.

The contents of the cutbuffer can be pasted at the current cursor position with ^U.

A line of text can be copied into the cutbuffer (without cutting it) with M-6.


3.5 The Mark

Text can be selected by first ’setting the Mark’ with ^6 or M-A and then moving the cursor to the other end of the portion to be selected. The selected portion of text will be highlighted. This selection can now be cut or copied in its entirety with a single ^K or M-6. Or the selection can be used to limit the scope of a search-and-replace (^\) or spell-checking session (^T^T).

On some terminals, text can be selected also by holding down Shift while using the cursor keys. Holding down the Ctrl or Alt key too will increase the stride. Such a selection is cancelled upon any cursor movement where Shift isn’t held.

Cutting or copying selected text toggles off the mark automatically. If needed, it can be toggled off manually with another ^6 or M-A.


3.6 Search and Replace

One can search the current buffer for the occurrence of any string with the Search command (default key binding: ^W). The default search mode is forward, case-insensitive, and for literal strings. But one can search backwards by pressing M-B, search case sensitively with M-C, and interpret regular expressions in the search string with M-R.

A regular expression in a search string always covers just one line; it cannot span multiple lines. And when replacing (with ^\ or M-R) the replacement string cannot contain a newline (LF).


3.7 Using the Mouse

When mouse support has been configured and enabled, a single mouse click places the cursor at the indicated position. Clicking a second time in the same position toggles the mark. Clicking in the two help lines executes the selected shortcut. To be able to select text with the left button, or paste text with the middle button, hold down the Shift key during those actions.

The mouse will work in the X Window System, and on the console when gpm is running.


3.8 Anchors

With M-Ins you can place an anchor (a kind of temporary bookmark) at the current line. With M-PgUp and M-PgDn you can jump to an anchor in the backward/forward direction. This jumping wraps around at the top and bottom.

When a line with an anchor is removed, the line where the cursor ends up inherits the anchor. After performing an operation on the entire buffer (like formatting it, piping it through a command, or doing an external spell check on it), any anchors that were present are gone. And when you close the buffer, all its anchors simply disappear; they are not saved.

Anchors are visualized in the margin when line numbers are activated.


3.9 Limitations

The recording and playback of keyboard macros works correctly only on a terminal emulator, not on a Linux console (VT), because the latter does not by default distinguish modified from unmodified arrow keys.


4 The Help Viewer

The built-in help in nano is available by pressing ^G. It is fairly self-explanatory. It documents the various parts of the editor and the available keystrokes. Navigation is via the ^Y (Page Up) and ^V (Page Down) keys. ^X exits from the help viewer.


5 The File Browser

When in the Read-File (^R) or Write-Out menu (^O), pressing ^T will invoke the file browser. Here, one can navigate directories in a graphical manner in order to find the desired file.

Basic movement in the file browser is accomplished with the arrow and other cursor-movement keys. More targeted movement is accomplished by searching, via ^W or w, or by changing directory, via ^_ or g. The behavior of the Enter key (or s) varies by what is currently selected. If the currently selected object is a directory, the file browser will enter and display the contents of the directory. If the object is a file, this filename and path are copied to the status bar, and the file browser exits.


6 Command-line Options

nano takes the following options from the command line:

-A
--smarthome

Make the Home key smarter. When Home is pressed anywhere but at the very beginning of non-whitespace characters on a line, the cursor will jump to that beginning (either forwards or backwards). If the cursor is already at that position, it will jump to the true beginning of the line.

-B
--backup

When saving a file, back up the previous version of it, using the current filename suffixed with a tilde (~).

-C directory
--backupdir=directory

Make and keep not just one backup file, but make and keep a uniquely numbered one every time a file is saved — when backups are enabled. The uniquely numbered files are stored in the specified directory.

-D
--boldtext

For the interface, use bold instead of reverse video. This will be overridden by setting the options titlecolor, statuscolor, keycolor, functioncolor, numbercolor, and/or selectedcolor in your nanorc file. See set keycolor for details.

-E
--tabstospaces

Convert each typed tab to spaces — to the number of spaces that a tab at that position would take up.

-F
--multibuffer

Read a file into a new buffer by default.

-G
--locking

Enable vim-style file locking when editing files.

-H
--historylog

Save the last hundred search strings and replacement strings and executed commands, so they can be easily reused in later sessions.

-I
--ignorercfiles

Don’t look at the system’s nanorc file nor at the user’s nanorc.

-J
--guidestripe

Draw a vertical stripe at the given column, to help judge the width of the text. (The color of the stripe can be changed with set stripecolor in your nanorc file.)

-K
--rawsequences

Interpret escape sequences directly, instead of asking ncurses to translate them. (If you need this option to get some keys to work properly, it means that the terminfo terminal description that is used does not fully match the actual behavior of your terminal. This can happen when you ssh into a BSD machine, for example.) Using this option disables nano’s mouse support.

-L
--nonewlines

Don’t automatically add a newline when a text does not end with one. (This can cause you to save non-POSIX text files.)

-M
--trimblanks

Snip trailing whitespace from the wrapped line when automatic hard-wrapping occurs or when text is justified.

-N
--noconvert

Disable automatic conversion of files from DOS/Mac format.

-O
--bookstyle

When justifying, treat any line that starts with whitespace as the beginning of a paragraph (unless auto-indenting is on).

-P
--positionlog

For the 200 most recent files, log the last position of the cursor, and place it at that position again upon reopening such a file.

-Q "regex"
--quotestr="regex"

Set the regular expression for matching the quoting part of a line. The default value is "^([ \t]*([!#%:;>|}]|//))+". (Note that \t stands for a literal Tab character.) This makes it possible to rejustify blocks of quoted text when composing email, and to rewrap blocks of line comments when writing source code.

-R
--restricted

Restricted mode: don’t read or write to any file not specified on the command line. This means: don’t read or write history files; don’t allow suspending; don’t allow spell checking; don’t allow a file to be appended to, prepended to, or saved under a different name if it already has one; and don’t make backup files. Restricted mode can also be activated by invoking nano with any name beginning with r (e.g. rnano).

-S
--softwrap

Display over multiple screen rows lines that exceed the screen’s width. (You can make this soft-wrapping occur at whitespace instead of rudely at the screen’s edge, by using also --atblanks.) (The old short option, -$, is deprecated.)

-T number
--tabsize=number

Set the displayed tab length to number columns. The value of number must be greater than 0. The default value is 8.

-U
--quickblank

Make status-bar messages disappear after 1 keystroke instead of after 20. Note that option -c (--constantshow) overrides this. When option --minibar or --zero is in effect, --quickblank makes a message disappear after 0.8 seconds instead of after the default 1.5 seconds.

-V
--version

Show the current version number and exit.

-W
--wordbounds

Detect word boundaries differently by treating punctuation characters as parts of words.

-X "characters"
--wordchars="characters"

Specify which other characters (besides the normal alphanumeric ones) should be considered as parts of words. When using this option, you probably want to omit -W (--wordbounds).

-Y name
--syntax=name

Specify the syntax to be used for highlighting. See Syntax Highlighting for more info.

-Z
--zap

Let an unmodified Backspace or Delete erase the marked region (instead of a single character, and without affecting the cutbuffer).

-a
--atblanks

When doing soft line wrapping, wrap lines at whitespace instead of always at the edge of the screen.

-b
--breaklonglines

Automatically hard-wrap the current line when it becomes overlong. (This option is the opposite of -w (--nowrap) — the last one given takes effect.)

-c
--constantshow

Constantly display the cursor position (line number, column number, and character number) on the status bar. Note that this overrides option -U (--quickblank).

-d
--rebinddelete

Interpret the Delete and Backspace keys differently so that both work properly. You should only use this option when on your system either Backspace acts like Delete or Delete acts like Backspace.

-e
--emptyline

Do not use the line below the title bar, leaving it entirely blank.

-f file
--rcfile=file

Read only this file for setting nano’s options, instead of reading both the system-wide and the user’s nanorc files.

-g
--showcursor

Make the cursor visible in the file browser (putting it on the highlighted item) and in the help viewer. Useful for braille users and people with poor vision.

-h
--help

Show a summary of command-line options and exit.

-i
--autoindent

Automatically indent a newly created line to the same number of tabs and/or spaces as the previous line (or as the next line if the previous line is the beginning of a paragraph).

-j
--jumpyscrolling

Scroll the buffer contents per half-screen instead of per line.

-k
--cutfromcursor

Make the ’Cut Text’ command (normally ^K) cut from the current cursor position to the end of the line, instead of cutting the entire line.

-l
--linenumbers

Display line numbers to the left of the text area. (Any line with an anchor additionally gets a mark in the margin.)

-m
--mouse

Enable mouse support, if available for your system. When enabled, mouse clicks can be used to place the cursor, set the mark (with a double click), and execute shortcuts. The mouse will work in the X Window System, and on the console when gpm is running. Text can still be selected through dragging by holding down the Shift key.

-n
--noread

Treat any name given on the command line as a new file. This allows nano to write to named pipes: it will start with a blank buffer, and will write to the pipe when the user saves the "file". This way nano can be used as an editor in combination with for instance gpg without having to write sensitive data to disk first.

-o directory
--operatingdir=directory

Set the operating directory. This makes nano set up something similar to a chroot.

-p
--preserve

Preserve the ^Q (XON) and ^S (XOFF) sequences so data being sent to the editor can be stopped and started.

-q
--indicator

Display a "scrollbar" on the righthand side of the edit window. It shows the position of the viewport in the buffer and how much of the buffer is covered by the viewport.

-r number
--fill=number

Set the target width for justifying and automatic hard-wrapping at this number of columns. If the value is 0 or less, wrapping will occur at the width of the screen minus number columns, allowing the wrap point to vary along with the width of the screen if the screen is resized. The default value is -8.

-s "program [argument …]"
--speller="program [argument …]"

Use the given program to do spell checking and correcting. By default, nano uses the command specified in the SPELL environment variable. If SPELL is not set, and --speller is not specified either, then nano uses its own interactive spell corrector, which requires either hunspell or GNU spell to be installed.

-t
--saveonexit

Save a changed buffer without prompting (when exiting with ^X). This can be handy when nano is used as the composer of an email program.

-u
--unix

Save a file by default in Unix format. This overrides nano’s default behavior of saving a file in the format that it had. (This option has no effect when you also use --noconvert.)

-v
--view

Don’t allow the contents of the file to be altered: read-only mode. This mode allows the user to open also other files for viewing, unless --restricted is given too. (Note that this option should NOT be used in place of correct file permissions to implement a read-only file.)

-w
--nowrap

Do not automatically hard-wrap the current line when it becomes overlong. This is the default. (This option is the opposite of -b (--breaklonglines) — the last one given takes effect.)

-x
--nohelp

Expert mode: don’t show the two help lines at the bottom of the screen. This affects the location of the status bar as well, as in Expert mode it is located at the very bottom of the editor.

Note: When accessing the help system, Expert mode is temporarily disabled to display the help-system navigation keys.

-y
--afterends

Make Ctrl+Right and Ctrl+Delete stop at word ends instead of beginnings.

-!
--magic

When neither the file’s name nor its first line give a clue, try using libmagic to determine the applicable syntax.

-%
--stateflags

Use the top-right corner of the screen for showing some state flags: I when auto-indenting, M when the mark is on, L when hard-wrapping (breaking long lines), R when recording a macro, and S when soft-wrapping. When the buffer is modified, a star (*) is shown after the filename in the center of the title bar.

-_
--minibar

Suppress the title bar and instead show information about the current buffer at the bottom of the screen, in the space for the status bar. In this "minibar" the filename is shown on the left, followed by an asterisk if the buffer has been modified. On the right are displayed the current line and column number, the code of the character under the cursor (in Unicode format: U+xxxx), the same flags as are shown by --stateflags, and a percentage that expresses how far the cursor is into the file (linewise). When a file is loaded or saved, and also when switching between buffers, the number of lines in the buffer is displayed after the filename. This number is cleared upon the next keystroke, or replaced with an [i/n] counter when multiple buffers are open. The line plus column numbers and the character code are displayed only when --constantshow is used, and can be toggled on and off with M-C. The state flags are displayed only when --stateflags is used.

-0
--zero

Hide all elements of the interface (title bar, status bar, and help lines) and use all rows of the terminal for showing the contents of the buffer. The status bar appears only when there is a significant message, and disappears after 1.5 seconds or upon the next keystroke. With M-Z the title bar plus status bar can be toggled. With M-X the help lines.


Option -z (--suspendable) has been removed. Suspension is enabled by default, reachable via ^T^Z. (If you want a plain ^Z to suspend nano, add bind ^Z suspend main to your nanorc.)


7 Feature Toggles

Toggles allow you to change certain aspects of the editor while you are editing, aspects that you would normally specify via command-line options or nanorc options. Each toggle can be flicked via a Meta-key combination — the Meta key is normally the Alt key (see Commands for more details). The following global toggles are available:


Constant Cursor Position Display

M-C toggles the -c (--constantshow) command-line option.

Smart Home Key

M-H toggles the -A (--smarthome) command-line option.

Auto Indent

M-I toggles the -i (--autoindent) command-line option.

Cut From Cursor To End-of-Line

M-K toggles the -k (--cutfromcursor) command-line option.

Long-Line Wrapping

M-L toggles the -b (--breaklonglines) command-line option.

Mouse Support

M-M toggles the -m (--mouse) command-line option.

Line Numbers

M-N toggles the -l (--linenumbers) command-line option.

Tabs To Spaces

M-O toggles the -E (--tabstospaces) command-line option.

Whitespace Display

M-P toggles the displaying of whitespace (see Whitespace).

Soft Wrapping

M-S toggles the -S (--softwrap) command-line option.

Expert

M-X toggles the -x (--nohelp) command-line option.

Syntax Coloring

M-Y toggles syntax coloring, when your nanorc defines syntaxes (see Syntax Highlighting).

Hidden Interface

M-Z toggles the -0 (--zero) command-line option, but without the -x (--nohelp) part. That is: it toggles just the title bar plus status bar (or the combined minibar plus status bar), not the help lines. The latter are toggled with M-X.


8 Nanorc Files

Nanorc files can be used to configure nano to your liking without using command-line options. During startup nano will normally read two files: first the system-wide file, /etc/nanorc (the exact path may be different on your system), and then the user-specific file, either ~/.nanorc or $XDG_CONFIG_HOME/nano/nanorc or .config/nano/nanorc, whichever exists first. However, if --rcfile is given, nano will skip the above files and will read just the specified settings file.

A nanorc file can contain set and unset commands for various options (see Settings). It can also contain commands that define syntax highlighting (see Syntax Highlighting) and commands that rebind keys (Rebinding Keys). Each command should be on a separate line, and all commands should be written in lowercase.

Options that do not take an argument are unset by default. So using the unset command is only needed when wanting to override a setting from the system’s nanorc file in your own nanorc. Options that take an argument cannot be unset, but can be assigned the empty string.

Any command-line option overrides its nanorc setting, of course.

Quotes inside the characters parameters below should not be escaped. The last double quote on the line will be seen as the closing quote.


8.1 Settings

The supported settings in a nanorc file are:

set afterends

Make Ctrl+Right and Ctrl+Delete stop at word ends instead of beginnings.

set allow_insecure_backup

When backing up files, allow the backup to succeed even if its permissions can’t be (re)set due to special OS considerations. You should NOT enable this option unless you are sure you need it.

set atblanks

When soft line wrapping is enabled, make it wrap lines at blank characters (tabs and spaces) instead of always at the edge of the screen.

set autoindent

Automatically indent a newly created line to the same number of tabs and/or spaces as the previous line (or as the next line if the previous line is the beginning of a paragraph).

set backup

When saving a file, back up the previous version of it, using the current filename suffixed with a tilde (~).

set backupdir "directory"

Make and keep not just one backup file, but make and keep a uniquely numbered one every time a file is saved — when backups are enabled with set backup or --backup or -B. The uniquely numbered files are stored in the specified directory.

set boldtext

Use bold instead of reverse video for the title bar, status bar, key combos, function tags, line numbers, and selected text. This is overridden by setting the options titlecolor, statuscolor, keycolor, functioncolor, numbercolor, and/or selectedcolor.

set bookstyle

When justifying, treat any line that starts with whitespace as the beginning of a paragraph (unless auto-indenting is on).

set brackets "characters"

Set the characters treated as closing brackets when justifying paragraphs. This may not include blank characters. Only closing punctuation (see set punct), optionally followed by the specified closing brackets, can end sentences. The default value is ""')>]}".

set breaklonglines

Automatically hard-wrap the current line when it becomes overlong.

set casesensitive

Do case-sensitive searches by default.

set constantshow

Constantly display the cursor position on the status bar. Note that this overrides quickblank.

set cutfromcursor

Use cut-from-cursor-to-end-of-line by default, instead of cutting the whole line.

set emptyline

Do not use the line below the title bar, leaving it entirely blank.

set errorcolor [bold,][italic,]fgcolor,bgcolor

Use this color combination for the status bar when an error message is displayed. The default value is bold,white,red. See set keycolor for valid color names.

set fill number

Set the target width for justifying and automatic hard-wrapping at this number of columns. If the value is 0 or less, wrapping will occur at the width of the screen minus number columns, allowing the wrap point to vary along with the width of the screen if the screen is resized. The default value is -8.

set functioncolor [bold,][italic,]fgcolor,bgcolor

Use this color combination for the concise function descriptions in the two help lines at the bottom of the screen. See set keycolor for valid color names.

set guidestripe number

Draw a vertical stripe at the given column, to help judge the width of the text. (The color of the stripe can be changed with set stripecolor.)

set historylog

Save the last hundred search strings and replacement strings and executed commands, so they can be easily reused in later sessions.

set indicator

Display a "scrollbar" on the righthand side of the edit window. It shows the position of the viewport in the buffer and how much of the buffer is covered by the viewport.

set jumpyscrolling

Scroll the buffer contents per half-screen instead of per line.

set keycolor [bold,][italic,]fgcolor,bgcolor

Use this color combination for the shortcut key combos in the two help lines at the bottom of the screen. Valid names for the foreground and background colors are: red, green, blue, magenta, yellow, cyan, white, and black. Each of these eight names may be prefixed with the word light to get a brighter version of that color. The word grey or gray may be used as a synonym for lightblack.

On terminal emulators that can do at least 256 colors, other valid (but unprefixable) color names are: pink, purple, mauve, lagoon, mint, lime, peach, orange, latte, rosy, beet, plum, sea, sky, slate, teal, sage, brown, ocher, sand, tawny, brick, crimson, and normal — where normal means the default foreground or background color. On such emulators, the color may also be specified as a three-digit hexadecimal number prefixed with #, with the digits representing the amounts of red, green, and blue, respectively. This tells nano to select from the available palette the color that approximates the given values.

Either fgcolor or ,bgcolor may be left out, and the pair may be preceded by bold and/or italic (separated by commas) to get a bold and/or slanting typeface, if your terminal can do those.

set linenumbers

Display line numbers to the left of the text area. (Any line with an anchor additionally gets a mark in the margin.)

set locking

Enable vim-style lock-files for when editing files.

set magic

When neither the file’s name nor its first line give a clue, try using libmagic to determine the applicable syntax. (Calling libmagic can be relatively time consuming. It is therefore not done by default.)

set matchbrackets "characters"

Specify the opening and closing brackets that can be found by bracket searches. This may not include blank characters. The opening set must come before the closing set, and the two sets must be in the same order. The default value is "(<[{)>]}".

set minibar

Suppress the title bar and instead show information about the current buffer at the bottom of the screen, in the space for the status bar. In this "minibar" the filename is shown on the left, followed by an asterisk if the buffer has been modified. On the right are displayed the current line and column number, the code of the character under the cursor (in Unicode format: U+xxxx), the same flags as are shown by set stateflags, and a percentage that expresses how far the cursor is into the file (linewise). When a file is loaded or saved, and also when switching between buffers, the number of lines in the buffer is displayed after the filename. This number is