Using the Nano Text Editor

A comprehensive guide to the Nano command line text editor, covering basic to advanced usage and options

Author: Jeremy Morgan
Published: December 16, 2023


Coding with AI

I wrote a book! Check out A Quick Guide to Coding with AI.
Become a super programmer!
Learn how to use Generative AI coding tools as a force multiplier for your career.


Nano is a free and open-source text editor that can be used on most Unix-like operating systems. It was originally designed as a clone of the popular command-line text editor Pico, but has since evolved into its own distinct tool with several unique features.

In this article, we will take a closer look at how to use Nano in Linux and explore some of its key features. We’ll start by introducing you to the basics of opening and using Nano, including navigation, editing, and saving files. Then, we’ll delve into some more advanced features like searching for text, viewing multiple windows at once, and creating macros.

How to Open Nano in Linux

Nano runs in the command line, and is to be used as a command line app. Many people prefer it over Vim or Emacs for text editing at the command line.

Using Command Line:

To launch Nano using the terminal, simply type

nano

without any parameters. This will open a new Nano window and automatically create a file called “Untitled” for you to edit.

“nano command in Linux”

If you want to open an existing file instead of creating a new one, just specify which file to work on. For example:

nano myfile.txt

You can also create multiple Nano windows. This will allow you to view and edit multiple files at once.

For example:

nano myfile1.txt myfile2.txt

“nano command in Linux”

If you want to close all open Nano windows, simply type “Ctrl + X” to exit Nano.

Working with Files in Nano

Once you’ve opened a file in Nano, you can navigate through it using the arrow keys and the home key (or “h”). You can also use “Ctrl + f” to search for text within the file. When you find what you’re looking for, press “Enter” to go to that location.

To save your changes to a file, simply hit “Ctrl + X”. This will prompt you to confirm whether you want to save your changes or not. If you do, type “Y” and press “Enter”. Alternatively, if you don’t want to save your changes, just press “N” without typing anything else.

“nano command in Linux”

Shortcuts

Here are some basic shortcuts for working with files in Nano:

File handling

  • Ctrl+S Save current file
  • Ctrl+O Save as
  • Ctrl+R Insert a file into current one
  • Ctrl+X Close buffer, exit from nano

Editing

  • Ctrl+K Cut current line into cutbuffer
  • Alt+6 Copy current line into cutbuffer
  • Ctrl+U Paste contents of cutbuffer
  • Alt+T Cut until end of buffer
  • Ctrl+] Complete current word
  • Alt+3 Comment/uncomment line/region
  • Alt+U Undo last action
  • Alt+E Redo last undone action

There are plenty more, and you can go to the help page (Ctrl + G) and see even more options:

“nano command in Linux”

Command Line Options

You can also work with Nano from the command line. Here are some options available:

Usage: nano [OPTIONS] [[+LINE[,COLUMN]] FILE]...

To place the cursor on a specific line of a file, put the line number with
a '+' before the filename.  The column number can be added after a comma.
When a filename is '-', nano reads data from standard input.

 Option         Long option             Meaning
 -A             --smarthome             Enable smart home key
 -B             --backup                Save backups of existing files
 -C <dir>       --backupdir=<dir>       Directory for saving unique backup files
 -D             --boldtext              Use bold instead of reverse video text
 -E             --tabstospaces          Convert typed tabs to spaces
 -F             --multibuffer           Read a file into a new buffer by default
 -G             --locking               Use (vim-style) lock files
 -H             --historylog            Save & reload old search/replace strings
 -I             --ignorercfiles         Don't look at nanorc files
 -J <number>    --guidestripe=<number>  Show a guiding bar at this column
 -K             --rawsequences          Fix numeric keypad key confusion problem
 -L             --nonewlines            Don't add an automatic newline
 -M             --trimblanks            Trim tail spaces when hard-wrapping
 -N             --noconvert             Don't convert files from DOS/Mac format
 -O             --bookstyle             Leading whitespace means new paragraph
 -P             --positionlog           Save & restore position of the cursor
 -Q <regex>     --quotestr=<regex>      Regular expression to match quoting
 -R             --restricted            Restrict access to the filesystem
 -S             --softwrap              Display overlong lines on multiple rows
 -T <number>    --tabsize=<number>      Make a tab this number of columns wide
 -U             --quickblank            Wipe status bar upon next keystroke
 -V             --version               Print version information and exit
 -W             --wordbounds            Detect word boundaries more accurately
 -X <string>    --wordchars=<string>    Which other characters are word parts
 -Y <name>      --syntax=<name>         Syntax definition to use for coloring
 -Z             --zap                   Let Bsp and Del erase a marked region
 -a             --atblanks              When soft-wrapping, do it at whitespace
 -b             --breaklonglines        Automatically hard-wrap overlong lines
 -c             --constantshow          Constantly show cursor position
 -d             --rebinddelete          Fix Backspace/Delete confusion problem
 -e             --emptyline             Keep the line below the title bar empty
 -f <file>      --rcfile=<file>         Use only this file for configuring nano
 -g             --showcursor            Show cursor in file browser & help text
 -h             --help                  Show this help text and exit
 -i             --autoindent            Automatically indent new lines
 -j             --jumpyscrolling        Scroll per half-screen, not per line
 -k             --cutfromcursor         Cut from cursor to end of line
 -l             --linenumbers           Show line numbers in front of the text
 -m             --mouse                 Enable the use of the mouse
 -n             --noread                Do not read the file (only write it)
 -o <dir>       --operatingdir=<dir>    Set operating directory
 -p             --preserve              Preserve XON (^Q) and XOFF (^S) keys
 -q             --indicator             Show a position+portion indicator
 -r <number>    --fill=<number>         Set width for hard-wrap and justify
 -s <program>   --speller=<program>     Use this alternative spell checker
 -t             --saveonexit            Save changes on exit, don't prompt
 -u             --unix                  Save a file by default in Unix format
 -v             --view                  View mode (read-only)
 -w             --nowrap                Don't hard-wrap long lines [default]
 -x             --nohelp                Don't show the two help lines
 -y             --afterends             Make Ctrl+Right stop at word ends
 -!             --magic                 Also try magic to determine syntax
 -%             --stateflags            Show some states on the title bar
 -_             --minibar               Show a feedback bar at the bottom
 -0             --zero                  Hide all bars, use whole terminal

Conclusion

Nano is a powerful and versatile text editor that can be used for a wide range of tasks on Linux systems. In this article, we’ve explored the basics of using Nano, including how to open it, work with files, and create macros. We hope you find these tips and tricks helpful in your daily use of Nano!


Coding with AI

I wrote a book! Check out A Quick Guide to Coding with AI.
Become a super programmer!
Learn how to use Generative AI coding tools as a force multiplier for your career.


Questions or Comments? Yell at me!

- Jeremy