Table of Contents

Introduction to the Nano Text Editor

Nano is an easy-to-use terminal based text editor that's both simple and versatile. Nano is available on all CS department Linux lab and research computers. It's a clone of the old Pico editor.

There are other command line text editors available such as Vim and Emacs but I recommend Nano as the easiest to learn. Some people recommend Vim and you can Google how to use Vim if you want.

Running Nano

Nano is a command line text editor so you need to open a terminal. In the CS Department's Linux lab you can find MATE Terminal in the upper left menu under Applications –> System Tools.

From the terminal command prompt, starting Nano is easy.

nano /path/to/filename

Nano will open that file if it exists. If it does not exist, it’ll start a new buffer with that filename in that directory.

Type Nano <filename> to start the Nano editor.

Using Nano

Let’s take a look at the default nano screen.

Ignore the top top lines which are part of the terminal and not the Nano editor

These lines will be different, or non existant, depending on the terminal used.

This is NOT part of the Nano Editor

At the top, you’ll see the name of the program and version number, the name of the file you’re editing, and whether the file has been modified since it was last saved. If you have a new file that isn’t saved yet, you’ll see “New Buffer.”

In the middle, you’ll see the contents of your document, a body of text.

The third-line from the bottom is a “system message” line that displays information relevant to the program executing a function. Here, you can see that it says “New File.”

The two rows at the bottom are the shortcut lines. This is where the most common shortcuts can be found like Control+o to save and Control+x to save & exit.

Editing with Nano

Nano is a WYSIWYG editor; “what you see is what you get.” What you type directly goes into the text input, unless you modify it with a key like Control or Meta. It’s pretty simple, so type some text out, or copy something and paste it into your terminal.

Note: As with many programs, copying text from Microsoft Products can induce unexpected characters so watch what you paste. Quotes and emdashs (—) are often problematic so watch those.

Beowulf is a 1,000 year old Nordic poem. You should read it. https://www.bl.uk/collection-items/beowulf

Nano Shortcut Keys

Program functions in Nano are referred to as “shortcuts”, such as saving, quitting, justifying, etc. The most common ones are listed at the bottom of the screen, but there are many more that aren’t.

Note: All shortcuts use lowercase letters and unmodified number keys, so Ctrl+G is NOT Ctrl+Shift+G.

Hit Ctrl+G to bring up the Help documentation and scroll down to see a list of valid shortcuts

Shortcuts are written as follows: Control-key sequences are notated with a '^' and can be entered either by using the Ctrl key or pressing the Esc key twice. Meta-key sequences are notated with 'M-' and can be entered using either the Alt, Cmd, or Esc key, depending on your keyboard setup. Also, pressing Esc twice and then typing a three-digit decimal number from 000 to 255 will enter the character with the corresponding value. The following are the most common keystrokes available in the main editor window.

^G    (F1)      Display this help text
^X    (F2)      Close the current file buffer / Exit from nano
^O    (F3)      Write the current file to disk
^R    (F5)      Insert another file into the current one

^W    (F6)      Search forward for a string or a regular expression
^\    (M-R)     Replace a string or a regular expression
^K    (F9)      Cut the current line and store it in the cutbuffer
^U    (F10)     Uncut from the cutbuffer into the current line

^J    (F4)      Justify the current paragraph
^T    (F12)     Invoke the spell checker, if available
                Invoke the linter, if available
                Invoke formatter, if available

^C    (F11)     Display the position of the cursor
^_    (M-G)     Go to line and column number

M-U             Undo the last operation
M-E             Redo the last undone operation

You can see the rest by using the Ctrl+G shortcut.

You can always use the Home, End, Page Up, Page Down, and the arrow keys to get around but it is faster to use the letter keys.

To move the cursor forward or backward, you can type Ctrl+F and Ctrl+B. To move up and down one line at a time, you can type Ctrl+P and Ctrl+N. In other words, you can use those keys instead of the Right, Left, Up, and Down arrows, respectively. Missing the Home and End keys? You can use Ctrl+A and Ctrl+E. Want to move pages at a time instead? Ctrl+V moves down a page, and Ctrl+Y moves up a page.

To move forward and backward one word at a time, you can use Ctrl+Space and Meta+Space (remember, that’s Alt+Space). And, if you’re really in a rush, you can hit Ctrl+_ and then type in the line number, a comma, and the column number to jump to a line #.

Copying, Cutting, and Pasting in Nano

When we want to copy text in graphical environment, we highlight it with the cursor. Similarly, in nano we “mark” it by using the Ctrl+^ command. You simply move the cursor to where you want to start marking, and then you hit Ctrl+^ to “set” it. This will mark everything between the starting point up to and NOT including the cursor.

To copy the marked text, hit Meta+^. If, instead, you want to cut the text, hit Ctrl+K.

To Paste your text, move the cursor to a suitable position and hit Ctrl+U.

Note: Cutting and pasting with the cursor usually works, (but not in all setups) in Nano as long as you limit yourself to what you can see on the screen.

Searching in Nano

If you want to search for a text string, hit Ctrl+W, and enter your search term. This search can then be cancelled mid-execution by hitting Ctrl+C without destroying your buffer.

The previous search term appears in the square brackets, and leaving the line blank and hitting Enter will repeat that last search.

Lorem Ipsum is the dummy text of the printing and typesetting industry.

Exiting Nano

Use Ctrl+X to exit Nano.

Type exit to close a terminal.