Intro to Nano text editor

by Richard White

2020-10-18

Description of nano and its Use

nano is the name of a text editor that is available by default in most Linux and Mac computers. It is also available on Windows computers that have the Ubuntu/Linux subsystem enabled.

A text editor is useful for writing text files, including program (source) files in Python and Java. Most people writing programs do so on their own computer using a text editor like VSCode or an Integrated Development Environment (IDE) like BlueJ. If you are working on a Mac or Linux machine, you could also write your programs using the nano text editor, available from the Terminal. If you don't have access to your own computer--perhaps it is lost, broken, or temporarily unavailable--you can always use a different computer to log on to the course server and write your code their using nano.

One of the advantages of being able to use a text editor like nano is that you can log onto a server if needed and create simple documents there. If you are new to this process, you will especially like the fact that many of nano's most useful commands are listed at the bottom of the screen.

This document will introduce you to the basics of nano:

Opening, Saving, and Closing a File

  1. To use the nano text editor, open a Terminal on your computer.

  2. To open a file using nano type

    nano filename
    

    and hit [Enter]. If the file exists, nano will open it. If the file doesn't exist, nano will open a blank window for you to enter text into.

  3. To save a file at any time, hold down the control key (indicated by a ^) press the o key to "write Out" the file to the disk. nano will display the filename that it thinks you want to save it under. Press [Enter] to accept the default filename, or type in something else if you want to save this copy under a different name.

  4. When you're done editing the file, press control-X, for eXit. If you have made any recent changes that haven't yet been saved, nano will ask you if you want to save them and give you the chance to do so. If there are no unsaved changes, nano will exit immediately.

Navigating through a file

Once a file is open you can move around through the file by issuing different commands. You cannot use the mouse/trackpad to navigate through the file when using nano! You'll need to use the keyboard.

A list of useful commands:

You can, of course, use the arrow keys to move around as well, but these simple commands will make it much easier to cover ground quickly in your text file.

Making changes to a file

When you make changes to a file, you can press ^o to write out (save) those changes as you go. If you try to exit nano without saving your changes, nano will remind you that you have a "modified buffer," and ask you if you want to save the changes. Y will cause nano to ask you what name you want to save the file under, and display the current name of the file (at which time you can just hit [Enter]), or ask you to name the file. If you say N to saving the changes, nano will quit without saving your most recent edits.

Getting further help with nano

You can get further information about the nano text editor by pressing ^g while you're in the editor, or by searching online for "nano tutorial" or "nano introduction."

Good luck!