SSH VPS

How to Install and Use Nano Text Editor

How to install and use Nano text editor

In this tutorial, you will learn how to install and use Nano text editor. It will let you conveniently edit text files on a web server via the command line when logged in using SSH. By the end, you’ll know how to set up Nano on the most popular Linux distributions and posses the knowledge of basic nano commands for text editing.

While Vim and Emacs can be overwhelming for novice Linux users, Nano is straightforward and easy to use. That’s why it’s one of the most popular text editors for Unix systems! In fact, it’s included by default on all our products, including web hosting, business hosting, and virtual private servers.

Before you begin this guide, you’ll need access to a machine running Ubuntu or CentOS or any other major Linux distro (remote SSH access will also work).

Without further ado, let’s dive in!

1. How to Install Nano Text Editor

The process depends on the operating system you are running. In particular, some of them already come with the Nano text editor pre-installed. If that is your case, you can go ahead to skip this section to start learning the basic Nano text editing commands.

Installing Nano on Debian/Ubuntu

To install Nano text editor on Debian or Ubuntu machines, execute the following command:

sudo apt-get install nano

Wait for all the processes to finish and the Nano setup will be complete.

IMPORTANT: sudo part is meant for running this command as a root user. This means you may be prompted to enter a password in case you are not logged into as a root user at the moment.

Installing Nano on CentOS/RHEL

To install the Nano text editor on CentOS or RHEL based platforms, run this command:

yum install nano

That is basically it for the installation. As soon as the setup ends, you’ll be ready to use it!

2. How to Use Nano Text Editor

In this part, we’ll dive into the usage of Nano text editor. We will cover:

  • How to open and close files.
  • Text editing tips and tricks.
  • Searching and replacing text.
  • Basic commands.

Opening and Closing the Nano Editor

The main command to open the editor is:

nano filename

Instead of the filename value, you can enter any desired value. Keep in mind that if you want to edit an existing file, you must be in the directory where the file is located. Alternatively, you can specify the full path to the file.

For example, to open a file in the current working directory:

nano example.php

It will open a new text editor window and if you make any changes, they will be saved under the same file name. To open a file in another directory use:

nano /path/to/directory/test.txt

Nano will create a new file with the given name if it is not present in the specified directory. If no name has been specified, it will create an empty untitled file and will ask for a name when exiting the editor.

After running the command, you will be taken to the editor window where you can now freely edit the file with the Nano text editor. Use arrow keys on your keyboard to move the cursor around the text.

Nano editor window with text commands

At the bottom of this window, you can find some shortcuts to use with the Nano editor. Symbol ^ means that you must press CTRL + [Key] (CMD + [Key] for Mac users) to use the chosen command.

To save the changes made in the file and continue editing press CTRL + O.

To exit from the editor press CTRL + X. If any changes have been made to the currently open file, it will ask whether to save them or not otherwise it will exit right away. Input for yes, or n for no, and then press ENTER.

BONUS TIP: whenever you are opening an important configuration file, use the -w option. By default, nano wraps the file text to fit the display. This may break some configuration files and may cause problems. For example when opening a config file use:

sudo nano -w /etc/apache2/apache2.conf

Editing Text

In order to select text go to the beginning of the text and press ALT + A. This will set a mark for selecting, then move over the text to be selected with the arrow keys.

To copy the selected text press ALT + 6. This will copy text to the clipboard. To cut text press CTRL + K.

If you want to paste text press CTRL + U. If no text is selected before copying or pasting, it will copy/cut the entire line.

Searching / Replacing Text

To search in the text press CTRL + W. It will ask you for the text to be searched. Insert your value and press ENTER. To continue searching for the same text string, ALT + W.

If your goal is to find and replace text, press CTRL+W and then CTRL+R. It will ask for the search text and the text to be replaced by. Afterward, the editor will take you to the first instance of the text and ask you whether to replace it or all of the occurrences.

Basic Nano Text Editor Commands

Here are some basic nano commands that come in handy while using the editor.

CommandExplanation
CTRL + AJump to the beginning of the line.
CTRL + EJump to the end of the line.
CTRL + YScroll page down.
CTRL + VScroll page up.
CTRL + GThis command will bring up a Help window which has information regarding all the commands you can use with the Nano editor.
CTRL + OBasically a save command. When used, you will be prompted to edit or verify the desired file name and after pressing enter, it will save your file.
CTRL + WOne of the most useful commands. It’s used to search for a specified phrase in your text. It works much like the usual CTRL+F command on other apps and platforms. To search for the same phrase again press ALT + W.
CTRL + KCuts the entire selected line to the “cut buffer”.
CTRL + UPastes the text from the “cut buffer” into the selected line.
CTRL + JJustifies the current paragraph.
CTRL + CShows the current cursor position in the text (line/column/character).
CTRL + XExits Nano text editor. In case you made any changes to the file, it will additionally prompt a save request.
CTRL + ROpen a file with “Read File” command. Inserts file from disk at the current cursor position.
CTRL + \Replace string or a regular expression.
CTRL + TInvoke the spell checker, if available.
CTRL + _Go to specified line and column number.
ALT + ASelect text. First, move the cursor to the beginning of a specific part of the text which you want to select, then press ALT + A. Now move the cursor with arrow keys to the right, this will start marking/selecting text. You can combine this command with CTRL + K to cut a specific part of the text to the “cut buffer”.

Those are the basic, most useful commands to use with the Nano text editor. For more commands, don’t forget that you can use CTRL + G to bring up the Help window.

Further Reading

Looking to learn more server management basics? Here are a few interesting articles:

Conclusion

In this tutorial, you have learned how to install Nano text editor on the most popular Linux distributions. You also know basic text commands among other useful tips and tricks. Now, you can effortlessly perform text editing tasks without having to download and re-upload the whole file.

Add Comment

Click here to post a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

More in SSH, VPS
How to Install Git on Ubuntu 14.04

Close