Nanorc, configure different aspects of the nano text editor

about nanorc

In the next article we are going to take a look at nanorc. Nano is a very lightweight command line text editor. Many Gnu / Linux system administrators use Nano for basic editing of configuration files. Personally, I prefer to use Vim. but this editor has a slight learning curve that Nano does not have.

In this article, we will see how perform some Nano text editor settings. For this we will use the file nanorc. Through this configuration file we will be able to configure this text editor system wide. We can also create a specific configuration for each user. In that case, you will have to create a file called .nanorc, in the directory HOME of the user you want to configure Nano for.

In the following lines we will see some of the most basic configuration options that Nano has. We will be able to use the file ~ / .Nanorc for a particular user or the file for the whole system / etc / nanorc. The settings will work for both options.

Configure Nano using the nanorc file

The file ~ / .Nanorc does not exist in users' home directory by default. But you can create one very easily. You just have to open a terminal (Ctrl + Alt + T) and write in it:

touch nanorc

touch ~/.nanorc

We can edit configuration file that we just created by typing:

clean nano configuration file

nano ~/.nanorc

The file ~ / .Nanorc it should be opened with the Nano text editor. Now, here you will be able to write the options that interest you.

save nano settings

Once you are done, you should save the file. To save the file, press Ctrl + x. Keep pressing S and then Intro.

Line number display

Nano does not display the line number by default. Next, we will see how display line numbers using file ~ / .Nanorc o / etc / nanorc.

For a particular user type in the terminal (Ctrl + Alt + T):

nano ~/.nanorc

To display the line numbers, write inside the file:

set linenumbers in file home nanorc

set linenumbers

Save the file, exit to terminal and reopen any other file on your system, without using sudo. As you will see, the numbers of each of the lines are displayed.

line number in nano

For show the line numbers in nano system wide, open the file / etc / nanorc with the following command:

sudo nano /etc/nanorc

As you can see in the following screenshot, all nano options are here. Most of them are disabled, commented at the beginning with #.

nano / etc / nanorc configuration file

To display the line numbers, find the dialed line shown in the following screenshot.

uncomment set linenumbers in / etc / nanorc

Now remove the comment at the beginning of the line and save the file.

Enable automatic indentation

autoindent nanorc set

Automatic indentation is not enabled by default in the Nano text editor. However, we can use the option autoindent set in the File ~ / .Nanorc or uncomment on / etc / nanorc for enable auto indent in the Nano text editor.

Enable mouse

nanorc mouse set

If you are using the Nano text editor in a graphical desktop environment, you can also use the mouse to move around the. To enable this function, you must use the option set mouse in the File ~ / .Nanorc or in / etc / nanorc.

Enable smooth scrolling

set smooth nanorc file

You can use set smooth in the File ~ / .Nanorc or in / etc / nanorc for enable smooth scrolling.

Tab Size Settings

set tabsize nanorc

In the Nano text editor, the default tab size is 8 characters wide. That is too much for most people. Personally, I prefer a tab size of 4 characters.

To define the size of the tab, say to 4 characters wide, we will use the following option in the file ~ / .Nanorc or in / etc / nanorc.

set tabsize 4

We can vary this size to taste.

Changing the color of the title bar

set title color

We can change the color of the title bar using the following option in the file ~ / .Nanorc or in / etc / nanorc. Here, the supported colors are:

white, black, blue, green, red, cyan, yellow, magenta

For example, let's say we want set title bar background color to green and foreground / text color to red, the option to put in the file ~ / .Nanorc or in / etc / nanorc should be.

set titlecolor red,green

Change of other colors

other color options for nanorc

We can change colors in other parts of the text editor. Apart from titlecolor, there are other options like: statuscolor, keycolor, functioncolor o numbercolor. These options are used in the same way as the color option for the title.

Help

In the more detailed information, you can check the nanorc man page by typing the command:

man nanorc

man nanorc

If you prefer, you can also consult the official documentation from the editor. We will see that there are many more options to configure the Nano text editor. It is beyond the scope of this article to cover each and every one of them. This is just the basics.


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.