Beginner

How to work with Nano Editor in Linux

How to work with Nano Editor in Linux
0
(0)

The Linux distribution has various editors, some of which are more popular than others due to their ubiquity and ease of use. Among the editors mentioned in this field are VI, VIM and Nano. In this tutorial, we are going to introduce you to how to work with Nano Editor in Linux.

One of the reasons that make Nano Editor more popular and easier than other editors is the type of editing and working with it. So that after executing this command in the Linux terminal, it is as if it has given you a graphic mode for text editing, which makes editing easier and faster. In the following, we will teach you how to work with Nano Editor in Linux. Stay with us.

How to work with Nano Editor in Linux

To execute the nano command, just type nano in the terminal environment. If you encounter an error, it is likely that nano is not installed on your Linux. Use the following commands to install nano:

Use the following command to install Nano on CentOS and RHEL Linux:

yum install -y nano

Use the following command to install Nano on Debian and Ubuntu Linux:

apt-get install nano

After installing Nano, you can use it as follows.

Note: The sudo section is intended to run this command as a root user. You may be asked to enter your password if you may not have logged in with the root user from the beginning. So no worries.

For example, to edit a file named Elder.txt, enter the following command:

nano Elder.txt

Once the file is opened, you can simply apply the desired changes and finally save the file.

Recommended Article: How to Install Termineter On Debian 10

Text editing tips and tricks

To select a text, scroll to the beginning of the text and press ALT + A. Then use the arrow keys to move the text.

Press ALT + 6 to copy the selected text. This copies the text to the clipboard.

Use CTRL + K to cut the text. If you want to paste the text, press CTRL + U.

How to search and replace text

Press CTRL + W to search for text. You are being asked what phrase are you looking for? Enter the text you want to search and press ENTER. Use ALT + W to continue searching for a similar text string.

If your goal is to search and replace text, press CTRL + W and then press CTRL + R. This will search and replace the text. After that, the editor takes you to the first instance of the text and asks you if all the found phrases are replaced or not?

Nano commands in Linux

Here are some nano commands:

Ctrl + G: Go to the help section of the nano command

Ctrl + A: Go to the first line of the document

Ctrl + E: Go to the last line of the document

Ctrl + Y: Like page down in Windows, you will be redirected to a page.

Ctrl + V: Like Page up in Windows, you will be redirected to a page.

Ctrl + C: Find the courser to type

Ctrl + W: Search the document

Ctrl + D: Delete the character that the courser is on.

Ctrl + K: Clear the entire line on which the courser is located.

Ctrl + O: Save the document

Ctrl + X: Exit the document with a message to save the document.

Nano Editor Settings

1. Smooth Scrolling

nano supports two types of scrolling. One is chunk-by-chunk, which scrolls multiple lines, and the other is line-by-line. By default, nano scrolls in multiple lines. To scroll line by line or softly (that is, scroll up or down by just pressing the arrow keys), add the following line to the settings:

set smooth

Or use the following switch when running nano:

-S or --smooth

2- Auto Indentation

This option is also very useful for programmers. The logic is that it calculates the indentation based on the distances of the previous line. Add this line in the settings file:

set autoindent

Or use the following switch at runtime:

-i or --autoindent

3- Backups

Be sure to enable this feature. Extremely useful.

Imagine you manipulated a system configuration file and now there is a problem with the system and you do not remember what you changed. With this option, every time you manipulate a file, nano will keep a copy of the unmodified version.

Add the following line in the settings file:

set backup

Or use the following switch at runtime:

-B or --backup

By default, backups are stored next to the original file, but one of the great things about nano is that you can ask it to keep all the backups in a specific path.

In the configuration file, add the following line and enter your desired address:

set backupdir "/home/user/nano-backups"

4- Nano history

If you need to access the search / replace history in nano, just add the following line to the configuration file. The history of all searches is stored in the ~/.nano-history file.

set historylog

You can also use the following switch to save history:

-H or --historylog

5- Activate the mouse

Although using a mouse with these types of editors will only slow down, it may be useful for actions such as copying or cutting.

set mouse

Here are the runtime options:

-m or --mouse

For a complete list of available options, get help from nano help:

nano --help or man nano

Conclusion

With the help of Nano Text Editor, you can easily edit text files on a web server via the command line using SSH. In this tutorial, you will learn how to install a nano text editor. Note that depending on the Linux operating system you have, you must enter the relevant command in the command line environment. There are some basic instructions and application keys that can help you edit your files faster and easier. You do not need to install Nano next time and just use the file editing command. You do not need to install Nano next time and just use the file editing command.

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

We Are Waiting for your valuable comments and you can be sure that it will be answered in the shortest possible time.

Leave a Reply

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

We are by your side every step of the way

Think about developing your online business; We will protect it compassionately

We are by your side every step of the way

+8595670151

7 days a week, 24 hours a day