Skip to main content
Racing Turtles

Nano - Edit Text With Simplicity and Speed

Get started using GNU Nano in the commandline.




Introduction #

Text editors and IDEs let you write code in comfort. Quick edits in the terminal prove more difficult. The other text editors nd IDEs available do more than necessary and need a steep learning curve. You could brew a coffee before you open VS Code. Grant yourself luck quitting Vim. Emacs gets you lost in its operating system. Terminal text editors don't need complexity.

GNU Nano fixes this and lets you edit files quickly in the terminal. You only need one terminal command and minimal keybinding memorization. This tutorial will help you get started using GNU Nano.

Requirements #

Getting Started #

On OS X and Linux, nano comes pre-installed.

To start nano, open a terminal emulator and enter nano in the shell.

$ nano

This opens the GNU nano text editor. The terminal should look something like this:

GNU nano start screen

The bottom of the terminal screen lists many commands along with what they do with ^ indicating Ctrl+.

Help Screen #

To access the help screen, press ^g/<C-g>. This brings up the help screen, which should look something like this:

GNU Nano help screen

Scroll one page at a time with the <PgUp> and <PgDn> keys. Several commands are listed along with their respective keybindings.

Close Help #

To close out of the help screen, press ^x/<C-x>. You should be taken back to the buffer you were previously editing.

Edit File #

To edit a file, start typing. Nano's start screen opens to an editable buffer that lets you to edit text without needing to change modes or wait for plugins to start.

Press <Enter> to insert a new line character or '\n'.

Save File #

To save a file:

  1. Type ^o/<C-o>.
  2. Type the location of the file relative to the present working directory.
  3. Press <CR>/<Enter>.

Press ^c or <C-c> during this process to cancel the file save.

Nano lets you use the <Up>, <Down>, <Left>, and <Right> keys to move the cursor up, down, left, and right respectively, assuming a character above, below, to the left, and to the right respectively exist.

The cursor can move one line below the last line of the file despite no text present there.

Scroll Vertically #

Nano lets you move the cursor vertically.

Scroll One Line #

To move the cursor the cursor up one line, press:

To move the cursor down one line, press:

Scroll One Page #

To move the cursor up one page at a time, press:

To move the cursor down one page at a time, press:

Scroll to Beginning or End of File #

To move the cursor to the beginning of the file, press:

To move the cursor to the end of the file, press:

Move Cursor Horizontally #

Nano lets you move the cursor horizontally.

Moving horizontally wraps to the next or previous line if the next occurrence is on the next or previous line respectively.

Move Cursor One Character #

To move the cursor left one character, press:

To move the cursor right one character, press:

Move Cursor One Word #

Nano lets you move one word to the left or right at a time. A word is an uninterrupted sequence of only non-whitespace characters.

To move the cursor one word to the left, press:

To move the cursor one word to the right, press:

Move Cursor to Beginning or End of Line #

To move the cursor to the beginning of the line, press:

To move the cursor to the beginning of the line, press:

Exit Nano #

To exit nano, press ^x/<C-x>.

If you saved your changes and didn't make new edits, Nano will exit, and you'll return to the terminal.

If you didn't save your changes, Nano will prompt for the location you want the buffer to be saved, with the opened file as the default path. Enter the name of the location you want to save the buffer to. Press <Enter> to save the file and exit Nano.

Conclusion #

GNU Nano was developed as a free replacement for the Pico text editor, later incorporated into Pine, later incorporated into Alpine. Pico's simplicity and ease-of-use drew users and inspired Chris Allegretta to develop a free replacement available for Linux. Since, Nano has been superceded by Vim and Emacs, text editors with much bigger userbases and plugin ecosystems. Despite its lack of popularity, Nano continues to be used for quick edits to files by even experienced Vim and Emacs users.

License #

This work is licensed under CC BY 4.0.