Linux Applications

Nano Editor, How to Guide for Beginners

Linux users have plenty of options to choose from when it comes to text editors. From basic to advanced, a lot of text editors are available on the internet. Advanced text editors like Vim and Emacs are not everyone’s cup of tea as you need to have some skills. Amateur users struggle to use these advanced text editors.

Nano is the best text editor for beginners as it is one of the most simple and easy-to-use text editors on Linux and its distributions, such as Ubuntu and LinuxMint.

Nano Text Editor:

Nano is simple and lightweight text editor especially developed for UNIX-like systems and desktop environments using a command-line interface. Nano is licensed under the GNU General Public License, and it emulates the Pico text editor.

How to Install Nano Text Editor:

I’m using Ubuntu for this tutorial, and the installation process will be the same on other Linux distros.

Before proceeding with the installation process, it would be a good idea to check if the Nano text editor is already installed or not on your system. Some Linux distros ship with Nano editor pre-installed.

To confirm, run the following command in Terminal.

$ nano - - version

If you get an output, as shown below screenshot, you can skip installation skip as Nano text editor is already installed on your system.

Installing Nano Text Editor is simple, just run the following command in Terminal and wait for the installation to complete.

$ sudo apt-get install nano

CentOS/ Red Hat Enterprise Linux (RHEL) users can use the following command to install Nano editor.

$ yum install nano

Now that the nano editor is successfully installed on your system and ready to use, we can start with a beginner’s guide to using the Nano text editor.

Guide to Use Nano Text Editor

In this part of the article, I will guide you through using the Nano text editor.

Before proceeding further, look at the following screenshot; it shows all the keyboard shortcuts you can use in the Nano text editor.

How to Open / Close the Nano Text Editor

The command to open Nano text editor is as follows.

$ nano filename

You can open various file types in Nano text editor, including .txt, .php, .html, and many others. You have just to type filename followed by an extension to open the particular file in Nano editor. For example, let’s say we have to open the file named linuxhint.txt, then the command will be as follows.

$ nano linuxhint.txt

You have to make sure you’re in the directory where the file is saved. If the file is not present in the directory, the Nano text editor will create a new file in the present directory.

The following screenshot shows the user interface of the Nano text editor. At the central part of the top of the editor window, the file name is mentioned.

While at the bottom part, you will see mostly shortcuts like cut, replace, go-to line, and justify. Here ˄ means CTRL key on the keyboard.

For example, to Write Out or save changes, you have to press the CTRL + O buttons on the keyboard.

If you’re opening a configuration file, make sure you use the – w option, this will command Nano editor to open the configuration file in a standard format. If you do not use this option, then Nano editor will wrap the file text to fit the window, which will eventually be difficult to read.

How to Search / Replace Text

CTRL + W is the shortcut to search the word in the editor. Now you have to enter the text you want to search and then press Enter key. To continue search further for the same text, use the ALT + W key.

To replace the text, you have to use CTRL + R. To begin; the editor will take you to the first instance of the text you wish to replace; to replace all the text, you have to press A. But if you want to replace one text, you have to press Y.

How to Copy Paste Text

Copy Paste operation is not as straight forwards as other text editors in Nano editor. If you wish to cut and paste a particular line, you must first bring the cursor at the start of that line.

Now you have to press CTRL + K to cut the line, then move the cursor to the place where you want to paste it, now finally, press CTRL + U to paste the line.

To copy-paste a particular string or word, you have to select that word or string by pressing CTRL + 6 or ALT + A, make sure the cursor is at the beginning of the word.

Now you can use CTRL + K and CTRL + U to cut and paste the word or string.

So, that’s it, that’s how you can start using Nano text editor and everything you needed to know about it. Editing a text file using the command line is not easy, but the Nano text editor makes it effortless. It is reliable and one of the easiest tools to use.

From novice users to professionals, everyone finds Nano text editor a useful command-line tool. I hope this guide has definitely helped you to get started with Nano editor.

About the author

Swapnil Tirthakar

A Software Engineer who loves football and passionate about traveling. I often spend my free time playing with gadgets and exploring new possibilities in tech world. I am Linux enthusiast and have about 6 years of experience in web development. I have good command on Python, Java, SQL and system security.