What is a nano editor
Nano Editor is a simple, display-oriented and free text editor that comes by default with all Linux operating systems. This is a good alternative to the non-free Pico, which comes by default with the Pine package. Programs like Vi and emacs may be more powerful, but Nano’s smart set of features makes it easy to learn and use for beginners. Inserting text and navigating through files is quite simple and includes only text input and basic cursor movement. Here we will explore all this and special key combinations that will make you a nano-guru.
Nano vs Pico
The user may choose Nano instead of Pico for the following reasons:
- Nano Editor is a very simple program with the minimal functionality needed to edit files.
- It has a built-in cheat sheet for shortcuts that appear at the bottom of the editor itself.
- It is available on most Linux systems.
- Nano Editor is a very stable program that almost never freezes, does not leak and does not crash.
- Syntax coloring can be used for many programming languages.
- It’s free!
Running Nano Editor on Linux
Nano for Linux is a terminal-based text editor, so first you need to open a terminal window. By opening a Linux terminal, you can open Nano with the following command:
You will see the following screen with a new open buffer / file:
As you can see above, the editor is divided into four main sections:
- The first line at the top displays the version number of Nano, the file name (in this case, the file name has not yet been specified) and whether the file has been changed or not.
- The line above the labels shown below shows system messages, such as status information from the system.
- The two lines of labels below provide the user with a set of commonly used labels.
To start Nano and create a new file to work, use the following command:
$ nano filename
The image below shows a file named filename.txt that we created to get around in practice.
Note. If you opened a new file / buffer without specifying a name using only the nano command, you can specify its name when saving the file. Please refer to the Saving File section for more information.
You can open an existing file using the following command:
$ nano [file-name]
This command will open the file if it exists in your current directory. You will have to provide the full path to the location if the required path exists elsewhere in your repository.
Work with files
You can navigate through the file using the arrow keys, but a faster way is to use keyboard shortcuts with keyboard letters, which are usually available in all environments.
Display cursor position
Sometimes you need to know the current cursor position in your file. Label CTRL + C Will not only highlight the cursor area, but also display location information in the status bar above the shortcuts.
Setting the cursor on a specific row and column at startup
You can configure the Nano editor to open an existing file with the cursor positioned on a specific row and column. You can use the following command to specify the row and column of the file when starting Nano:
$ nano + row, column [filename]
Copy, cut and paste text
Let’s start by writing some sample text that we can select, cut or copy and paste into our file. Highlighting text is very easy in Nano; hover over this text and select it using the keyboard or mouse.
To cut selected text, click Ctrl + K and then place the cursor where you want to paste the text. Now click Ctrl + U; You can see the text inserted at this position.
In this example, we selected the text “This is another example text” and copied it into the document through Ctrl + U,
Note. Use the keyboard shortcut Alt + ^ to copy text rather than cut it.
Text line cropping
Nano Editor also allows you to cut a line of text instead of the entire line. In the following example, we will cut the string “sample” from our text. Please select the line you want to cut by placing the cursor at the beginning of the line and clicking Ctrl + 6, This will mark the line as selected; the message “mark set” appears in the status bar.
Now place the cursor at the position where you want to insert the row and click Ctrl + UYou can see that the row was inserted in a new place in the following image:
Spellcheck your text
You can check the spelling of your text using the control: Ctrl + TAlthough Nano is not a word processor, this added feature helps you get the file without errors when it comes to writing.
To save the file, please use Ctrl + O label. Nano will ask you to enter a file name or re-confirm the file name if you have already specified it. Make the necessary changes and press Enter; Your file will be saved in the system.
The status bar will show the number of lines saved in your file as follows:
Insert one file into another
With Nano, you can combine the contents of one text file with another. Open the file and click Ctrl + R, The editor will ask you the name of the file whose text you want to insert into the current file. You can see that in the following image we entered the file name filnamet.txt,
In the following image, the selected row was inserted from the specified file.
Useful switches in nano
Nano Editor comes with a number of powerful switches. The most common and useful ones are listed below for your use; others can be found in the Nano Editor manual:
|nano-v||Use this switch to backup the file before editing it.|
|nano-e||Use this switch to convert tabs to spaces when editing your text.|
|nano s||Use this switch to continuously view statistics on cursor position.|
|nano||Use this switch to automatically indent a new line (s) at the same position as the previous line.|
|nano-k||Use this switch to switch the cropping (it trims the cursor position, rather than trimming the entire line of text).|
|nano||Use this switch to get mouse support.|
|nano-v||Use this switch to open files in read-only mode.|
Now you can create, edit and save Nano files after practice with this article. Using the powerful Nano keyboard shortcuts, you can easily edit your files, such as cut, copy and paste text, spell check your file, copy text from another file, etc. Therefore, in the end, being a nano guru is not so difficult. !
How to work with Nano Editor on Linux