Nano Editor in Linux

FREE Online Courses: Elevate Skills, Zero Cost. Enroll Now!

In this article, we will learn everything about the Nano editor in Linux-based operating systems. We will look at what the Nano editor is, why it is used, how to install it, and the options and keystrokes used while editing documents in the Nano editor. In the end, we will also look at some fantastic practical examples of the Nano editor by testing out the various keystrokes and combinations to understand its working. So pay attention, take notes, and read all the way to the end for the best benefits.

What is Nano editor in Linux?

The nano editor is a command line-based user-friendly text editor in Linux-based operating systems. With the advanced keystrokes and simple GUI, it is one of the most recommended and used text editors. The nano editor is one of the simplest text editors, however, don’t mistake it for the lack of features!

In Linux, there are many text editors like Vi, Gedit, Vim, Emacs and so many more. The one difference between all these and GNU nano is that it does not have any modes. Also, the learning curve for most of these, especially Vim and Emacs is very steep, unlike nano, which you can master in a couple of hours!

Despite its simplicity, the nano editor is feature loaded. Some include syntax highlighting, multiple buffers, search and replace with regular expression support, spellchecking, UTF-8 encoding, and so many more. Yup! Sound intimidating right?

Well, we will start right from the basics like how to create and open a file, edit a file, save a file, search and replace text, cut and paste text, and only then move to more advanced topics.

How to install the nano text editor?

Most of the Linux distributions already come with the Nano editor preinstalled. However, if your Linux distro does not have it, or if you uninstalled it, you can always install it using the commands shown below with respect to your Linux distro:

Installing Nano editor on Debian-based Linux distributions

If you want to download the Nano editor on Debian-based Linux distros like Kali, Ubuntu, Deepin, ParrotOS, Mint, MX Linux, Pure OS, AntiX, etc, use the command shown below:

sudo apt install nano

Installing Nano editor on Fedora-based Linux distributions

If you want to download the Nano editor on Fedora-based Linux distros like Berry Linux, Qubes, Fedora spins, Clear OS, Korora, Hanthana, Arquetype, etc, use the command shown below:

sudo yum install nano

Now that we have laid down the basics, let us look at some fantastic examples in the terminal of Ubuntu 20.04 to understand how to Nano text editor works.

Creating a new file

To create a file, there are 2 ways, let us look at both of them. The first method is to simply run an empty ‘nano’ command, write your text, and then while exiting (ctrl + X) press confirm and then write the name of the file as shown below:

writing the file name

 

Another method to create a new file is to simply specify the filename after the nano command as shown:

nano <filename>

creating a new file

You must note that if the filename you specified already exists, the nano editor will open that file instead of creating a new file, and this brings me to the next topic:

Opening an already existing file in nano editor

To open an already created file, simply run the nano command followed by the name of the file as shown:

nano <existing filename>

If you are simply writing the name of the file, you must make sure that it is present in your current working directory. However, if you want to open a file that is present elsewhere in your filesystem all you have to do is specify the path of the file as shown:

nano <path of file>

Closing files in nano editor

Closing files is even simpler! All you have to do is press the key combination “Ctrl” + “X”. Once you do so, the system prompts you to confirm by pressing either “y” for yes, “n” for no, or “^c” for cancel.

Now that we know how to create files and close them let us look at how to edit them. But first, here is a cheat code: you can press “ctrl” + “g” to display all of the possible key combinations that are used in the nano editor.

help menu of the nano editor

Searching a file in nano editor

To search for a specific word or a part of a text in a file, all you have to do is press the key combination “Ctrl” + “W”. This opens a prompt where you can enter the word or sentence that needs to be searched. This will show you all of the matches found, if you want to move to the next matched result, all you have to do is press the key combination “Alt” + “W”.

searching a file

Searching regular expressions in nano editor

Just like we searched normal strings, we can also search regular expressions by using the key combination “Alt” + “R”

Replacing text using nano editor

If you want to select some text and then replace it, we will have to first use the key combination “Ctrl” + “W” then use the key combination “Ctrl” + “R”. This will open a prompt where you can enter the text that you want to replace and one you press enter, you get to type the text you want to replace with.

replacing the text replacing the selected string

 

Selecting, copying, cutting, and pasting text in nano editor

No tutorial on handling text in a text editor is complete without the fundamental tasks of selecting, copying, cutting, and pasting, and you may have guessed by now that it is not as simple as “ctrl” + “a” for selecting, “ctrl” + “c” for copying and “ctrl” + “x” for cutting and “ctrl” + “p” for pasting.

Instead, the key combinations are slightly different, In the nano text editor we use the “alt” + “a” key combination and then use the arrow keys to move over the text. For copying text, we first select it and then use the key combination “Alt” + “6”, for cutting text, we use the key combination “Ctrl” + “k” and to paste copies or cut text, we use the key combination “Ctrl” + “u”.

Inserting another file into the current one in nano editor

While editing in the nano text editor you can even insert another text file into the one you are working on by using the key combination “Ctrl” + “R”. Once you use this key combination, you will get a prompt to enter the path of the file you wish to insert as shown below:

inserting another file into the current one

Saving a file in nano editor

We all know that saving a file in regular intervals is a good habit rather than waiting till the end to save it. In the nano text editor, we can save our file by using the key combination “Ctrl” + “o”.

Checking spellings in the nano editor

If you want to check your spellings in the nano editor, you will have to first install the package ‘instant spell’ by using the command shown below:

sudo apt install spell

checking spellings in the nano editor

Now that we have successfully installed the package, we can now check for spellings by using the key combination “Ctrl” + “T”. This will select the misspelled word and ask for a correct replacement.

Nano text editor key combination cheat sheet

If there is one thing that is slightly hard in the entire concept of nano editor in Linux-based operating systems, it will be to remember the various key combinations and to add to the twist, these key combinations are not the typical key combination you would use in your day to day activities on your PC. Well here is a cheat sheet containing 23 of the most frequently used key combinations in the nano editor:

1. move forward one character: Ctrl+F
2. move back one character: Ctrl+B
3. move forward one word: Ctrl+Space
4. move back one word: Alt+Space
5. move to the previous line: Ctrl+P
6. move to the next line: Ctrl+N
7. move to the next page: Ctrl+V
8. move to the previous page: Ctrl+Y
9. move to the beginning of the line: Ctrl+A
10. move to the end of the line: Ctrl+E
11. Copy the selected text: Alt+6
12. Cut the selected text: Ctrl+k
13. Paste the selected text: Ctrl+u
14. Cancel the selection: Ctrl+6
15. Undo last action: Ctrl+U
16. Redo last action: Ctrl+E
17. Searching for a text: Ctrl+w
18. Search and replace: Ctrl+\
19. Saving file: Ctrl+o
20. Inserting a file: Ctrl+r
21. Checking for spelling: Ctrl+t
22. Move the cursor to a certain location: Ctrl+_
23. Exiting the editor: Ctrl+x

Summary

As you have seen, the nano editor is a simple text editor in Linux based operating systems that is very user-friendly yet slightly advanced at the same time. You have now learned what the Nano editor is, why it is used, how to install it, and the options and keystrokes used while editing documents in the Nano editor.

You give me 15 seconds I promise you best tutorials
Please share your happy experience on Google

follow dataflair on YouTube

Leave a Reply

Your email address will not be published. Required fields are marked *