Nano/Guide

From Gentoo Wiki
< Nano(Redirected from Nano/Basics guide)
Jump to:navigation Jump to:search

This guide covers basic operations in nano, and is meant to be very concise. For more information about nano check out: https://www.nano-editor.org.

Note
In nano's help text, the Ctrl key is represented by a caret (^), so Ctrl + W is shown as ^W, and so on. The Alt key is represented by M ("Meta"), so Alt + W is shown as M-W.

Opening and creating files

To open or create files, type:

user $nano filename
Warning
Prior to version 4.0, when editing configuration files, always pass nano the -w option. Without this option, long lines are wrapped by inserting newlines - this will often break configuration files.

Nano is a modeless editor: start typing immediately to insert text. To edit a configuration file, such as /etc/fstab, for example:

root #nano /etc/fstab

Saving and exiting

To save the changes, press Ctrl + O. To exit nano, type Ctrl + X.

Trying to exit with unsaved changes, it will ask to save. Press N to discard changes. Press Y to save - it will then ask for a filename, type it in and press Enter. If save is confirmed accidentally, cancel by pressing Ctrl + C when prompted for a filename.

Cutting and pasting

To cut a single line, use Ctrl + K (hold down Ctrl and then press K). The line disappears. To paste it, move the cursor to where to paste, and punch Ctrl + U. The line reappears.

To move multiple lines, simply cut them with several Ctrl + K in a row, then paste with a single Ctrl + U.

For more fine-grained control, mark the text: move the cursor to the beginning of what should be cut, hit Ctrl + 6 (or Alt + A). Now move the cursor to the end of the text to be cut: the marked text gets highlighted (to cancel at this point, simply hit Ctrl + 6 again). Press Ctrl + K to cut the marked text. Use Ctrl + U to paste.

Searching for text

Searching for a string is easy, but think "WhereIs" instead of "Search". Simply hit Ctrl + W, type in the search string, and press Enter. To search for the same string again, hit Alt + W.

More options

Read /etc/nanorc for options.


This page is based on a document formerly found on our main website gentoo.org.
The following people contributed to the original document: Sherman Boyd
They are listed here because wiki history does not allow for any external attribution. If you edit the wiki article, please do not add yourself here; your contributions are recorded on each article's associated history page.

Thanks to kiyose and quazion from #gentoo (webchat).