37. Text Editor - Basic Usage of Nano
Contents
By using the nano text editor provided by Linux, we can easily do some simple text editing operations such as adding, deleting, modifying, etc.
Nano Version
We can take a look at the version of nano:
|
|

Checks the version of the nano we are currently using
Editable Mode
We can open a text editor that is editable by running the nano command directly:
|
|

Running the nano command

Nano editor opened in editable mode
Let’s fill in the editor with the following two lines:
|
|

Filling the contents
Write Content to a File
The symbol ^ (caret) corresponds to the ctrl key on our keyboard.
We can use the combination keys (Ctrl+O) to specify the name of the file that is used to hold the content:
|
|

A prompt shows up asking what the name of the file is

After pressing the enter key, nano saves the content to a text file named nano_file
We can use the combination keys (Ctrl+X) to exit nano program.
Let’s take a look at the contents of the file we just created through the nano editor:
|
|

Outputs the content of the newly created text file nano_file
Enable Mouse Operation
Nano also provides mouse support by adding the -m parameter:
|
|

Entering nano editor in mouse enabled mode, this will allow us to interact nano menus with mouse pointer
We can try clicking on the red box area in the screenshot shown above.

Now we are on the write out page
We can click the cancel option to exit to the editor page:

Now we are on the main page
We can click the exit option to exit the editor.
Viewable Mode
We can enter the view mode with the-v parameter provided by the nano tool, in which all of our edits on the specified file are invalid.
|
|

Open nano_file in viewable mode

Opened in viewable mode
As shown in the screenshot below, we can’t do any changes to the file inside viewable mode.

Typing something in the viewable mode
Edit an Existing File
We can use nano to edit an existing text file:
|
|

Opening a text file to edit

Editing the opened nano_file

Add another line

Write out page

Write out the edited content to existing nano_file

Outputs the edited nano_file
References Nano 2.3.x Command Manual
Author Dong Chen
LastMod Sat Mar 9 2019