LinuxCommandLibrary

nano

Edit text files

TLDR

Open specific files, moving to the next file after closing the previous one

$ nano [path/to/file1 path/to/file2 ...]
copy

Start the editor without using configuration files
$ nano [[-I|--ignorercfiles]]
copy

Open a file and position the cursor at a specific line and column
$ nano +[line],[column] [path/to/file]
copy

Open a file and enable soft wrapping
$ nano [[-S|--softwrap]] [path/to/file]
copy

Open a file and indent new lines to the previous line's indentation
$ nano [[-i|--autoindent]] [path/to/file]
copy

Open a file and create a backup file (path/to/file~) on save
$ nano [[-B|--backup]] [path/to/file]
copy

Open a file in restricted mode (i.e. don't read/write to files not specified on the command-line)
$ nano [[-R|--restricted]] [path/to/file]
copy

Exit nano
$ <Ctrl x>
copy

SYNOPSIS

nano [options] [filename(s)]
nano -h | --help
nano -v | --version

PARAMETERS

-A, --smarthome
    Enables the 'smart home' key behavior, where pressing Home once moves to the start of the line's text, and again to the true start of the line.

-B, --backup
    Creates backup files of the original content when saving modifications. Backups are typically saved with a '.bak' suffix.

-c, --constantshow
    Constantly displays the current line, column, and character position in the status bar.

-h, --help
    Displays a summary of command-line options and exits.

-i, --autoindent
    Enables auto indentation for new lines, inheriting the indentation level from the previous line.

-L, --linenumbers
    Displays line numbers in the left margin of the editor window.

-m, --mouse
    Enables mouse support, allowing clicking to position the cursor and selecting text.

-S, --smooth
    Enables smooth scrolling, making the text scroll gradually instead of jumping line by line.

-T <cols>, --tabsize=<cols>
    Sets the displayed width of a tab character to <cols> columns (default is 8).

-U, --multibuffer
    Enables the multiple file buffer feature, allowing the user to switch between editing different files within the same nano session.

-V, --view
    Opens the specified file(s) in read-only view mode, preventing accidental modifications.

-v, --version
    Displays the current nano version information and exits.

-w, --nowrap
    Disables soft wrapping of long lines, causing them to extend horizontally beyond the screen width.

DESCRIPTION

nano is a user-friendly command-line text editor for Unix-like operating systems. It was designed to be an easy-to-use replacement for the Pico editor, making it particularly popular among beginners due to its intuitive interface. Unlike more complex editors like Vim or Emacs, nano focuses on simplicity and ease of learning, making it ideal for quick edits of configuration files, scripts, or plain text.

Its interface displays common commands at the bottom of the screen, reducing the learning curve significantly. Key features include syntax highlighting for various file types, efficient search and replace functionality (with regular expression support), spell checking, automatic indentation, and support for multiple buffers (editing several files simultaneously). Its straightforward keybindings, often involving the Ctrl key, contribute to its accessibility, allowing users to quickly perform common tasks without extensive training.

CAVEATS

While nano excels in simplicity and ease of use, it lacks the advanced scripting, macro capabilities, and highly customizable environments found in more powerful editors like Vim or Emacs. This can limit its efficiency for complex programming tasks or large-scale file manipulations. Users accustomed to traditional command-line navigation might find its reliance on Ctrl key combinations less efficient than modal editing paradigms. Also, certain advanced terminal features might not always be fully supported across all environments.

KEYBINDINGS AND INTERFACE

nano's keybindings are typically displayed at the bottom of the screen, making it easy for new users to discover commands. Commands are prefixed with '^' (representing the Ctrl key) or 'M-' (representing the Alt or Meta key). For example, ^X means Ctrl+X (Exit), and ^O means Ctrl+O (WriteOut/Save). This direct display of common shortcuts is a core part of its beginner-friendly design, enabling users to perform tasks without memorizing complex commands.

CONFIGURATION FILE

Users can customize nano's behavior and default settings through a personal configuration file, typically located at ~/.nanorc. This file allows for persistent options such as enabling syntax highlighting for specific file types, setting default behaviors like line numbering or soft wrapping, and even defining custom keybindings or aliases for frequently used commands. This allows for personalization while retaining nano's core simplicity.

HISTORY

GNU nano was originally created in 1999 by Chris Allegretta as a free software replacement for the Pico editor. Pico, part of the Pine email client, was not free software, leading to a demand for an open-source alternative with similar ease of use. Initially named TIP (TIP isn't Pico), it was renamed to nano in 2000 to avoid a naming conflict with another Unix utility. Since then, it has been officially adopted by the GNU Project and has continuously evolved, focusing on maintaining its user-friendly interface while adding useful features like syntax highlighting and regular expression search, establishing itself as a popular choice for quick and simple text editing.

SEE ALSO

vim(1), vi(1), emacs(1), pico(1), less(1), cat(1)

Copied to clipboard