blog posts

How to use Nano Editor in Linux (Ubuntu/Debian/CentOS)

In Linux environments such as Ubuntu, Debian, and CentOS, one of the basic tasks of users is to edit files and texts. Editors play a very important role in this process, and choosing the right editor can improve the user experience. Two of the most powerful and popular command-line editors are Vim and Emacs. Both editors have a steep learning curve that can be intimidating for new users. For those looking for a simple editor, Nano is the best option. Nano Editor is a simple and efficient text editor available on many Linux distributions, and the features that distinguish it from other text editors include ease of use, access to utility commands, and support for syntax highlighting.

The nano editor is an open-source text editor for the Linux command line environment. This simple and efficient editor is used to edit and manage text files and programming codes. Installing Nano is recommended due to its simplicity and ease of working with it, small size, default presence in most Linux distributions, and useful features such as search and replace, save file,s and return to the previous state (Undo). This editor is suitable for quick and basic editing of files and helps command-line users, especially in terminal and server environments.

Nano includes all the basic features you’d expect from a regular text editor. Including spelling highlighting, multiple buffers, search and replace with regular expression support, ability to apply spelling correction, UTF-8 encoding, and other features.

This article will fully teach how to install the Nano editor in Ubuntu, Debian, and CentOS distributions and explain how to use it with clear examples. By following this tutorial, you will be able to easily edit files and texts in the Linux environment and benefit from the valuable features of the Nano editor.

If you are a fan of the Linux operating system, you can have it on your own virtual server, which you can directly purchase a Linux virtual server.

Table of Contents

  • Installing Nano software
  • Installing Nano software in Ubuntu and Debian
  • Installing Nano software on CentOS and Fedora
  • Open and create files in nano
  • Edit files in nano
  • Find and replace nano in Ubuntu, Debian and CentOS
  • Copy, paste, and cut in Nano editor
  • Save the changes and exit the nano editor
  • Nano Customization (nanorc)
  • Syntax highlighting
  • Set Nano as the default text editor
  • Basic use of nano

Installing Nano software

The Nano text editor comes pre-installed on Mac OS and most Linux distributions. To check if it is installed on your system, type the following command:

nano --version

 

You will see a result similar to the following:

GNU nano, version 2.9.3

(C) 1999-2011, 2013-2018 Free Software Foundation, Inc.

(C) 2014-2018 the contributors to nano

Email: nano@nano-editor.org Web: https://nano-editor.org/

If the nano software is not installed on your system, you can install it using your distribution’s package manager.

 

Installing Nano software in Ubuntu and Debian

To install nano on Ubuntu and Debian, run the following command:

sudo apt install nano



Installing Nano software on CentOS and Fedora

To install Nano software on CentOS and Fedora, run the following command:

sudo yum install nano

Open and create files in nano

To open an existing file or create a new file, just type nano and then enter the name of the file:

nano filename

 

 

Nano Editor allows you to open a new editor window and start editing the file.

At the bottom of the window is a list of basic command shortcuts for use with the nano editor.

All commands start with ^ or the letter M. The ^ symbol represents the Ctrl key. For example, ^J commands mean pressing Ctrl and J keys at the same time. The letter M represents the Alt key.

You can type Ctrl+g to get a list of all commands.

To open a file, you must have read access to the file.

If you want to open a file with a specific cursor position, you can use the following structure:

 

nano +line_number,character_number filename

 

If you omit the character number, the cursor will be placed on the first character.

Edit files in nano

Unlike the vi editor, nano is a stateless editor, meaning you can start typing and editing text immediately after opening the file.

To move the cursor to a specific line and character number, use the Ctrl+_ command. The menu list at the bottom of the page will change. Enter the number(s) in the field “Enter line number, column number:” and press Enter.

Find and replace nano in Ubuntu, Debian and CentOS

To search for a text, press Ctrl+w, type the search term, and press Enter. The cursor moves to the first match. Press Alt+w to move to the next match.

If you want to search and replace, press Ctrl+\. Enter the search term and the text you want to replace. The editor moves to the first match and asks if you want to replace it. After pressing Y or N, it will move to the next match. Pressing A replaces all matches.

Copy, paste and cut in nano editor

To select text, move the cursor to the beginning of the text and press Alt+a. This will set the selection indicator. Use the arrow keys to move the cursor to the end of the desired text. The selected text will be displayed. If you want to cancel the selection, press Ctrl+6.

Copy the selected text to the clipboard with Alt+6 command. Cut the selected text with Ctrl+k button.

If you want to cut clip lines, simply move the cursor to the desired line and press Ctrl+k. You can cut multiple lines by pressing Ctrl+k multiple times.

To paste the text, move the cursor to the desired location and press the Ctrl+u button.

 

Save the changes and exit the nano editor

Press Ctrl+o to save the changes you made to the file. If the file does not exist yet, it will be created when saving.

Press Ctrl+x to exit Nano. If there are unsaved changes, you will be asked if you want to save the changes.

To save the file, you must have write access to the file. If you are creating a new file, you must have write access to the folder where the file is being created.

Nano Customization (nanorc)

When nano runs, it reads its configuration parameters from the system configuration file etc/nanorc/ and from the user files config/nano/nanorc./~ and nanorc./~ if these files exist.

Options specified in user files take precedence over global options.

To see the complete list of all available options, you can visit the nanorc page.

Syntax highlighting

Nano has syntax highlighting rules for the most popular file types. On most Linux systems, syntax files are stored in the usr/share/nano/ directory and are included in the etc/nanorc/ configuration file by default.

To enable highlighting for a new file type, the easiest option is to copy the file containing the syntax highlighting rules to the usr/share/nano/ folder.

 

Set Nano as the default text editor

On many Linux systems, the default text editor for commands like visudo and crontab is set to vi. But to use the nano editor as the default text editor, you need to change the VISUAL and EDITOR environment variables.

Bash users can set these variables in the bashrc./~ file:

 

~/.bashrc

export VISUAL=nano

export EDITOR="$VISUAL"

 

Basic use of nano

Below are the basic steps to start using Nano:

At the command line, type nano, and then enter the filename.

Edit the file to your liking.

Use Ctrl+x to save changes and exit the editor.

Conclusion

According to the tutorial on installing and using nano editor in Ubuntu, Debian, and CentOS Linux systems, we can conclude that nano is a powerful and simple tool for editing files. Nano is very simple to install and as a modeless editor, it allows the user to start editing texts easily. By providing efficient command shortcuts and various features, Nano suits beginners and professional users.

Using Nano as a default text editor in Linux environments can significantly improve user experience and make editing and changing files easier. By following the instructions for installing and using the nano editor provided in this article, users can safely use this efficient editor to edit files. After completing this tutorial, we hope that you, as Linux users, will make Nano one of your favorite editors and make the experience of editing files easier by using this useful tool.