CSCI-1411-Using-nano

Quick Guide to Using nano

This guide describes the text editor nano and provides a quick introduction to using nano to author C++ source files.

This guide will show you how to open the nano application, create a C++ source file, save the file, and then exit.
This guide simply provides an introduction to using nano with some very basic commands. If you would like additional information on how to use nano there are many external resources. The more you use the program the better and more comfortable you will be using it.

HorizontalLine

Using nano to Create a C++ Source File

Step 0: Connect to the Unix CSE grid and login (The CSCI-1411 page contains guides on how to do this for both PC and Mac computers). Once you are at the Unix command line you can proceed to Step 1.

Step 1: Open the nano application by entering the command: nano and then pressing enter. This will open the nano application where you can start writing in a new file. If you would like to open an existing file then you can specify the file name after the command: nano test.cpp (If you give the file name and that file doesn’t exist then that is fine as well, nano will just know you intend to save the file under that name).

Nano open test.cpp

Nano open test.cpp

Step 2: Once nano is running you will be shown the screen below. Since nano is a simple text editor you can now type in the window as you would with any text editor. You can use the keys (but not the mouse) to navigate through the text that you write.

Nano Program Running

Nano Program Running

Step 3: Enter the following code to create a very simple C++ program (this is just an example, enter whatever code you would like).

Basic C++ Program in nano

Basic C++ Program in nano

Step 4: Now add a couple of comments to the code. They will be used to show you how to select, cut, and paste text. The following image shows the full C++ code with the added comments.

C++ Program with Comments

C++ Program with Comments

Step 5: To select text, move the cursor to where you would like to begin the selection, then press Ctrl+^ (that is the 6 key at the top of the keyboard – U.S.) Once you have pressed this short-cut move the cursor with the arrow keys to change what characters are selected. When you are happy with the text that is selected, press Ctrl+K to cut the text. Note: If you don’t select any text and use Ctrl+K it will cut the entire line that cursor is on.

Selecting text in nano (Ctrl+^)

Selecting text in nano (Ctrl+^)

Step 6: Move the cursor to the location where you would like to paste the text. When the cursor is at the correct location press Ctrl+U. This will paste the cut text at the new position. The following image shows that the word “Bottom” has been cut from the bottom comment and inserted into the top comment.

Nano Paste (Ctrl+U)

Nano Paste (Ctrl+U)

Step 7: When your done editing the file it can be saved by using the Ctrl+O short-cut (note that this is an ‘oh’ and not a Zero). Once you press the save short-cut you can enter the desired file name and press enter. This will save the file (if it reports that there is an existing file you can press ‘y’ for yes to overwrite the file).

Saving a file in nano

Saving a file in nano

If you need to look at any additional commands you can get the help page in nano by using the short-cut Ctrl+G