Getting started with Nano
In 1989, the University of Washington released a *nix email client named Pine. This client contained an integrated editor called Pico, which stood for Pine’s message composer, and was written in C. Pico was a simple editor which concentrated on working with a single document at a time.
In 1999, when issues with Pico’s licensing developed, Chris Allegretta created TIP in order to create a free software replacement. TIP, which stood for TIP isn’t Pico, was renamed to Nano in 2000 to avoid a conflict with a Unix tool called
tip. Nano became part of the GNU project in 2001, and as a result, Nano is sometimes referred to as GNU Nano.
This article will show you how to install Nano and provide you with basic commands to get you started.
Installing Nano on a Red Hat Enterprise Linux-based system is as easy as
sudo yum install nano, and unlike some editors, there is no additional configuration needed unless you wish to configure Nano to be your default editor. To make Nano the default for your whole system:
sudo cat <<EOF >> /etc/profile.d/nano.sh export VISUAL="nano" export EDITOR="nano" EOF
To make Nano a user’s default editor:
cat <<EOF >> ~/.bash_profile export VISUAL="nano" export EDITOR="nano" EOF
Then, to activate, simply type
./.bash_profile, or log out and then back in to reset your session.
Let’s explore the basic commands you’ll need to start using Nano.
Starting/editing a file
To open an existing file, or to create a new file, type
nano <filename>. If the file is or will be in a different directory, type
nano </path/to/filename>. No matter how you open the file, you begin on the edit screen:
There are several ways to get help with Nano. If you are on the command line, look at the man pages by typing
man nano, which will return the command-line options.
The other types of help are available within the program once you are editing. The first type is what I tend to call the "on-screen help," as it is visible on the bottom of your screen at all times (though this feature does vary if you are in the process of using one of Nano’s program functions via a shortcut). For instance, if you type the shortcut for justify, the shortcut for unjustify replaces one of the original options. Another example is when you search. The on-screen help changes to shortcuts you can use while searching.
To access Nano's main help, type Ctrl+G or Ctrl+g, as Nano is not case sensitive as far as shortcuts and searches.
If you access the help from the main editing screen, you are taken to the main help for Nano, which includes all of the different program functions and their shortcuts, as well as a brief explanation of each:
However, if you were to access the help from one of the program functions, you would find more specialized help similar to how the on-screen shortcuts change.
Searching (and replacing)
You can access the search function via the shortcut Ctrl+W, and it is not case sensitive as mentioned before. Another feature of this shortcut is that it will wrap the file, so if you started lower down in the text and there’s a match above, the search will wrap around to that spot:
If, while searching, you wish to replace the text or character that you are searching for, you can do so with the Ctrl+R shortcut. Note: if you have already searched to at least the first match, Ctrl+R will be for "Read File" so you will need to Ctrl+W and then Ctrl+R to do a search and replace. If a match is found, you are prompted to replace that instance with a
Y (yes) or
N (no), or to replace all instances, or to cancel the search and replace altogether.
You can move around in Nano while using the search function, or while editing. When in the search function, use the various shortcuts to move to the beginning or end of the line, paragraph, or the document itself (noted by first or last line). You can also go to a specific location within the document.
When moving while editing, you have the option to go to the previous page or the next page.
Cutting and pasting
As with most editors, you have the ability to cut (Ctrl+K) and paste (Ctrl+U) within Nano, though paste is referred to as Uncut. To cut a specific section of a line or lines, first mark your selection by using Ctrl+Shift+6 (Ctrl+^), and then move your cursor to the end of the selection, and use the Ctrl+^ shortcut again to cut the text out of the document.
Finding your location
Need to find out where your cursor is in the document? The Ctrl+C shortcut provides the line, column, character, and percent of the way through the document.
Justifying a paragraph re-spaces it so that all lines touch both the left and right edges by adding white spaces as needed. To justify your current paragraph, use the Ctrl+J shortcut; but similar to uncutting, you use the Ctrl+U shortcut to unjustify.
As mentioned when discussing Nano’s history, you can only work with one file at a time. However, you can insert another file into the document you are currently working on. To insert the other file in your current location within the document, use the Ctrl+R shortcut. You can then supply the file’s path by typing it, or use Ctrl+T to search through the filesystem.
Saving or writing out
There are times when you wish to save your document while editing, and without having to log out of the document. This situation can be referred to as saving or writing out. To do this, use the shortcut Ctrl+O, and you will be prompted for the filename to use (giving you the opportunity to save to a different file if you choose).
Exiting Nano is simple. You type Ctrl+X. You are given the opportunity to save the file, give it a new name, or not save at all. Or, you can choose not to exit the document after all.
Pros and cons
As you can see, Nano is pretty simple and straightforward to use. It is also extremely lightweight and at one point was the default editor, as well as the editor installed when in recovery mode. However, Nano does have its limitations, such as a smaller feature set than you would find in a more robust editor like Vim or Emacs, including the ability to work on more than one document at a time.