How to use and install Nano Text Editor on Linux

Tutorials

June 7, 2022 by Granit Emery

Use and Install Nano Text Editor

You will require a command-line environment in order to create or modify text files. For Unix and Linux operating systems, Nano is a popular text editor. Nano is a strong piece of software that allows you to modify and generate a variety of files.

For those seeking simplicity, Nano is an excellent option. It has all of the fundamental capabilities of other text editors, such as UTF-8 encoding, syntax highlighting, search and replace using regular expressions, multiple buffers, and spellchecking.

Install and utilize Nano text editor by following this tutorial.

How to install Nano Text Editor on Linux

Nano is a text editor that comes pre-installed on macOS and most Linux variants. Type the following to see whether it’s installed:

Nano -- version

As a result, you will see something like this:

GNU nano, version 2.9.3
(C) 1999-2011, 2013-2018 Free Software Foundation, Inc.
(C) 2014-2018 the contributors to nano
Email: nano@nano-editor.org	Web: https://nano-editor.org/

Alternatively, the process can be carried out in two stages if necessary.

  • Start by updating the apt repositories using the following command:
sudo apt update
  • After that, install Nano using these commands:

Debian/Ubuntu:

sudo apt install nano

CentOS/Fedora:

yum install nano

The text editor has been successfully installed.


Keep in mind that if you have specific files in each directory and you do not want your virtual server to be attacked repeatedly, changing the Linux VPS password once a month is a priority.

How to Use Nano Text Editor on Linux

Create and open files

To create or open a file, type nano followed by the filename.

nano filename

Make sure you’re in the right directory if you wish to make changes to an existing file. You may also enter the entire path of the file you’re looking for. In order to open a file, it must first have read rights.

nano /path/to/filename

You can write or edit it in the new editor window that opens. The cursor can be moved around the text with the arrow keys on your keyboard. A few shortcuts can be found at the bottom of this window. The ^ symbol means you have to press CTRL + [Key] (CMD + [Key] for Mac users) to execute the command you have chosen.

The file can be saved and edited by pressing CTRL + O. Typing Ctrl + G will also display a list of all commands.

You can exit the editor by pressing CTRL + X. It will ask you whether to save any changes you have made to the file currently open, otherwise it will end the session. Enter Y to indicate yes or N to indicate no, and then press ENTER.

 

Edit files

Nano is a modeless editor, so you can start editing as soon as you open the file. Press ALT + A at the beginning of the text to select it. By doing this, the text will be marked for selection, and you can then move the cursor over it with the arrow keys.

The selected text can be copied by pressing ALT + 6. The text will be copied to the clipboard. ALT + K can be used to cut text. CTRL + U is the shortcut for pasting text. It will copy or cut the entire line if there is no text selected before copying/pasting.

The selected text can be copied by pressing ALT + 6. The text will be copied to the clipboard. ALT + K can be used to cut text. CTRL + U is the shortcut for pasting text. It will copy or cut the entire line if there is no text selected before copying/pasting.

 

Exit and save the file

Using the Ctrl+O (^O) keyboard combination, you can save any changes you make in a document. A file name will be required or the name of an existing file will need to be confirmed. A new file will be created once it has been saved.

Press Ctrl+X to exit Nano (Nano displays it as ^X). You will be asked whether you would like to save any changes that have not been saved.

 

Select, Copy, Cut, and Paste Text

You can select parts of a file by navigating to the beginning of it, pressing Alt+A (M-A), and moving it over using the arrow keys. This will highlight the selection. Press Ctrl+6 to cancel the selection.

Copy the selected text using Alt+6 or the combination (M-6) and cut it with Ctrl+K (^K). The entire line of text will be copied or cut if you don’t select any text prior to using these shortcuts.

Press Ctrl+u when you want to paste the text where you want it.

 

Replacing and searching text

Use the “where-is” feature of the editor with Ctrl+W (^W) to find a specific word or part of a text. Enter the text you are looking for in the search box. Use Alt+W (M-W) to move on to the next result.

Searching by line number is also possible. You can then find a particular line by pressing Ctrl+T (^T) while in it.

A regex (regular expression) search is also possible. Regex search patterns are defined by character sequences. You can do this by pressing Alt+R (M-R) on your keyboard.

Use CTRL+W and CTRL+R to find and replace text. Type the text you want to find and the text you want to replace it with. Once the text has been removed, you will be taken to the first instance of the text and asked whether you would like to replace the entire instance or just the first instance.

 

Navigation shortcuts

Navigating through a large file quickly is important when working with a large file. Using the arrow keys or keyboard shortcuts is one way to do this in Nano.

You can navigate using the following keyboard shortcuts:

  • Ctrl+F (^F) to move one character forward
  • Ctrl+B (^B) to move one character back
  • Ctrl+Space (^Space) to move one word forward
  • Alt+Space (M-Space) to move one word back
  • Ctrl+P (^P) to move to the previous line
  • Ctrl+N (^N) to move to the next line
  • Ctrl+V (^V) to move to the next page
  • Ctrl+Y (^Y) to return to the previous page
  • Ctrl+A (^A) to move to the beginning of the line
  • Ctrl+E (^E) to move to the end of the line

 

Nano Spell Check

Nano’s spell-checking feature is also available. This feature requires the spell package to be installed.

Run the following command in the terminal to install the spell package:

sudo apt install spell

Press Ctrl+T (^T) to spell check in the text editor after installing the package. A misspelled word will be highlighted and asked to be replaced.

 

Make Nano your default text editor

Vi is the default text editor for most Linux systems. Changing VISUAL and EDITOR environment variables will make nano the default text editor.

For users of the Bash shell, variables can be exported in the ~/.bashrc file:

export VISUAL=nano
export EDITOR="$VISUAL"

Conclusion

It’s now time for you to install Nano on Linux! It was important for you to learn how to create, edit, and save files using basic text commands.

For additional commands, you can always use Ctrl+G (^G) to access the Help text.

 

FAQ

 

copy the sample.nanorc from the doc/ directory in the nano source package (or from /usr/doc/nano on your system) to .nanorc in your home directory, and then edit it. If you didn't get a sample nanorc, the syntax of the file is simple: features are turned on and off by using the words set and unset followed by the long option name of the feature (see man nanorc for the full list of options). For example, "set quickblank" or "set smarthome". Of course, for this to work, your nano must not have been compiled with --disable-nanorc.

Helpful

About the Author Granit Emery

Leave a Reply

Your email address will not be published.