How to show line numbers in GNU nano

There has been an ongoing debate within the Linux community about which is the best command-line editor. vim, emacs, nano, etc, each editor has its own pros and cons, but there’s no denying that nano is one of the most popular.

If you’re new to nano, you may wonder how to show the line numbers each time you opens a new file. This tutorial will answer just that.

Show current line number using a keyboard shortcut

If you’re already opening a file and don’t want to reopen it, you can press Ctrl + C to display the current line number.

Show line number dynamically using -c switch

nano can dynamically show you current line number without you having to press Ctrl +C every once in a while, but it requires reopening the file. Simply add -c switch and everytime you move, the line number updates automatically.

nano -c file.txt

Enable line number column in nano

If you want to show all line numbers (like what you’ve seen in almost all code editor), here’s a handy shortcut to do that : Alt + Shift + 3. Remember, you need to use the “3 and # key“, not the 3 key in the number area of your keyboard.

Permanently enable line numbering in nano

To make what you’ve just done permanent, nano uses a configuration in your home folder ~/.nanorc

Thus to display line numbers everytime you use nano, you need to put a line into .nanorc. This file doesn’t exist by default, so don’t worry if you haven’t seen it on your system before.

nano ~/.nanorc

Then, add set constantshow as a new line and save the file (Ctrl + O).

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading...

Leave a Reply

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