Trusted answers to developer questions

How to configure the Nano text editor on GNU/Linux

Get Started With Data Science

Learn the fundamentals of Data Science with this free course. Future-proof your career by adding Data Science skills to your toolkit — or prepare to land a job in AI, Machine Learning, or Data Analysis.

Nano is an easy-to-use and friendly command-line text editor for UNIX-like systems. It can be customized with command-line options or with the .nanorc file.

Improve the usability of Nano with command-line options

This is the simplest way to configure Nano. You need to add option(s) when calling Nano on your terminal like this:

Launch Nano
Launch Nano

As you can see on the image above, we will be opening the fizzbuzz.py file with the mouse support enabled on the command line. It means that mouse clicks can be used to place the cursor, set the mark (with a double click), and execute shortcuts. By default, the mouse is not supported on the console.

Note: If mouse support is not available on your system, e.g., you have installed a fully command-line system, this option can’t work for you.

Here are some other options you can use:

Option Description
-m or --mouse Enable mouse support
-i or autoindent Indent new lines to the previous line’s indentation. Useful when editing source code
-l or --linenumber Display line numbers to the left of the text area

Note: You can learn about more options by typing man nano on your terminal.

# Pros and cons

It helps you configure Nano very quickly, but you have to do it every time you want to use it. For that reason, there is another way to configure the text editor once for all that we discuss in the line below.

Configure Nano with .nanorc

Nanorc is the file configuration for Nano. You can do a local configuration, i.e., configuration for your profile (user) only, or a global configuration for all users on the computer.

Local .nanorc

Let’s create one in our home. On your terminal, make sure you are on your home (run $pwd). If not at home, do cd ~.

Run nano .nanorc (don’t forget the dot .). When the file opens, type these options (see below):

nanorc
nanorc

Save the file by doing Ctrl + X and hint Y (for yes).

The great advantage with this method is that your configuration is kept, and you don’t need to set it every time you use nano command.

Note: You can learn about more options by typing man nanorc on your terminal.

Global .nanorc

If you want to configure Nano for all users in your system, you have to use the global nanorc file.

To do so, open the /etc/nanorc (without the dot .) with the nano command and uncomment (delete # before an option) what you want. For this, you need root or sudo privilege.

Global nanorc
Global nanorc

Delete the # before the set autoindent option.

RELATED TAGS

linux
configuration

CONTRIBUTOR

Abel Lifaefi Mbula
Attributions:
  1. undefined by undefined
Did you find this helpful?