A Beginners Guide to the Nano Editor

The 'nano' editor is easy to use and probably already on your computer

Most Linux distributions include a text editor called nano as a standard utility. It's part of a family of text editors that includes the more robust (but significantly more complex) vi and emacs.

For most uses, nano is easy to use and it doesn't require a significant learning curve. In fact, just as with the 1980s-era text-based word processors like WordStar, nano offers a dynamic two-line command reference at the bottom of the terminal window.

Starting 'nano'

GNU nano editor window

Launch nano from a shell prompt by executing:

nano [option] /path/to/filename

Invoking nano without options and without a filename opens the editor full-screen within the terminal window.

Using 'nano'

As a text editor, nano isn't designed to create fancy reports. You won't find any special formatting options or font selections. Instead, you get a plain window, the last two lines of which contain a hot list of the most common tasks you can perform given the current state of the editor.

In both the toolbar and in the help text within the editor, key combos appear with standard Linux shortcut codes. The letter M stands for the meta key, which on most keyboards is the Alt key. The ^ symbol stands for Ctrl.

Standard commands include:

  • Get Help: Press Ctrl+G to display a complete list of commands and their hotkeys.
  • Exit: Close the program. You'll be prompted to save the current buffer or to exit without saving.
  • Write Out: Save the current buffer to the filesystem.
  • Read File: Open a file from the filesystem.
  • Where Is: Search for a text string.
  • Replace: Replace one text string for another.
  • Cut Text: Remove the current line of text.
  • Paste Text: Paste text from memory.
  • To Spell: Spell-check the current buffer.
  • Cur Pos: Display the position of the cursor relative to the contents of the buffer as a whole.
  • Go To Line: Move the cursor to a specific line number.

Special Commands

When you perform a command, the bottom two rows modify dynamically to fit the context of what you're doing. For example, when you save a buffer with the Ctrl+O hotkey, you'll see shortcut options to save the file in DOS or Mac format, append or prepend the buffer to an existing file, backup the file, or launch a text-based filesystem browsing utility.

Check Your Spelling

When you invoke the spell checker with the Ctrl+T hotkey, nano checks the spelling of the document. However, spell checking requires the spell package. If it's not installed, nano flags an error. Otherwise, it highlights every term not within the dictionary, prompting for a correction. The tool does not auto-correct spelling or even suggest alternative spellings.

Nano Switches

When you invoke nano from the shell prompt, specifying an optional command switch modifies the program's default behavior. The most useful switches are covered below; find the rest by reading the nano manual.

  • nano -B: Backs up the file prior to editing it 
  • nano -E: Converts tabs to spaces while you're editing
  • nano -c: Continuously display the cursor-position stats
  • nano -i: Automatically indent new lines to the same position as the previous line
  • nano -k: Toggle cut so that it cuts from cursor position instead of the whole line
  • nano -m: Provides mouse support to the editor
  • nano -v: Opens the file as read-only

After you master the basics of nano, check out the program's manpage for more detailed guidance. Enter man nano at a shell prompt.