How to Work with Nano Editor in Linux

How to Work with Nano Editor in Linux

Nano is a default command-based text editor in many Linux distributions. It is easy to use as compared to vi and vim editor. It has more functionality, replacement, and searching is easy. You do not need to memorize the shortcuts, it shows them in the editor.

In this tutorial, we are focusing on different features of Nano editor in Linux. We have used Red Hat Enterprise Linux 9.

Create a new file

You can create a file either at the beginning or end of writing in file while quitting the editor.

To create a new file suppose sample_file.txt, type on the terminal.

nano sample_file.txt

You can specify the file name while quitting the editor. In this case just type on the terminal:

nano

An editor will open. Type your text and click ctrl + X from the keyboard to close the file. Type y to save the file and specify the file name as shown below.

Copy the text

You can copy the text with the help of mouse and keyboard. Select the text with mouse movement and right click and then click Copy.

If you want to use your keyboard, move the cursor over an area from where you want to copy the text. Select shift + right/left scroll to select the text. When you are done with text selection, click ALT + 6 to copy the selected text.

Cut the text

You can cut the selected text with a keyboard shortcut CTRL + K.

Paste the text

Move the cursor where you want to paste the selected text. Right click and then click ‘paste’ with your mouse. With keyboard, you can press CTLR + U to paste the text where your cursor is positioned in the file.

Copy and paste from Nano to system/vice versa

You can use the keyboard shorcut to copy and paste the text from Nano editor to system and vice versa. To copy from Nano editor, select the text (by using one of the above methods) and press CTRL + SHIFT + C from the keyboard. This will copy the text into buffer which you can paste using CTRL + V.

To paste the text from the system to Nano editor, first select the text (with keyboard shortcut or mouse) and then press CTRL + SHIFT + V from the keyboard.

Save a file

You can save the file and continue writing in it by pressing CTRL + O from your keyboard and then press enter key.

If you want to save the file and quit the editor, type CTRL + X and editor will ask to save the modified buffer or not. Press y followed by Enter key from the keyboard.

Search and replace

You can search a file by pressing CTRL + W (W is short for where is). Upon entering the key combination you will be asked for the text you want to search. Input the text and press Enter key from the keyboard.

The editor will highlight and bring your cursor to the first match occurrence. Type CTRL + W and press Enter key again to move to next match occurrence.

To search and replace text, press CTRL + \ from the keyboard. The editor will first ask you to enter the text you want to search and press enter key, it will then prompt for the text you want to replace. Enter the text you want to replace and press Enter key.

Go to beginning and end of file

You can go to beginning of your file by typing CTRL + home or ALT + \ from the keyboard.

If you want to go to the end of file, use CTRL + end from the keyboard.

Conclusion

We have walked you through the different features of nano editor. If you liked it, share it with your colleagues and follow Linux World.