How to Show Line Numbers in Nano Editor?

Do you wish you had Nano line numbers? Well, now you can; read on to find out how to show line numbers in Nano editor.

Updated: 06 Feb, 24 by Antoniy Yushkevych 7 Min

List of content you will read in this article:

The nano editor is a text editor included in many Unix-based systems. It is a small, lightweight editor that is easy to use and perfect for making simple changes to text files. If you're new to the Nano text editor, you may wonder how to show line numbers in Nano. This can be helpful when working with long files or finding a specific line of code.

🔗 Explore our in-depth comparison of the top-rated 💻 text editors for Linux in 2024. 🚀 Check out the full list of "Best Linux Text Editors" to find the perfect one for your coding needs! 📝💡

Nano show line numbers on the left side of the Nano editor, which improves overall readability and convenience of editing, particularly in situations when accurate line identification is critical, such as debugging or code collaboration. Users may quickly access certain nano line numbers by looking to the left, allowing for a more intuitive and streamlined editing experience in the Nano editor.

📚 Explore more Nano Text Editor tips and tricks in our comprehensive guide on "How to Use Nano Text Editor"! 🚀

Using Shortcut Keys

The initial approach to nano show line number at the bottom of the Nano editor when you use the Arrow keys to travel up or down the file. In contrast, the second option displays nano line numbers in a column format on the left side of the Nano editor.

Now, let's look at some shortcut keys for nano show line numbers.

ALT+C

Pressing ALT+C in the Nano editor reveals the current line number at the bottom. Conversely, if the line numbers are already visible, using the same shortcut will hide them. To employ the ALT+C shortcut, begin by opening a sample file in Nano, for example:

$ sudo nano test.sh

Afterwards, press ALT+C to observe the result:

Crucially, the information bar persists at the bottom until we deactivate it using ALT+C or restart Nano. While it remains on the screen, the information dynamically updates as we navigate the cursor.

CTRL+C

Likewise, for nano show nano line numbers, CTRL+C serves as another key combination to achieve the same functionality of showing line numbers at the bottom of Nano.

Consequently, we observe the line number in the same format enabled by ALT+C. Nevertheless, unlike ALT+C, the CTRL+C shortcut provides a static snapshot and doesn't update as we move the cursor. Additionally, the information bar disappears after a brief period.

ALT+N

Alternatively, the ALT+N shortcut key allows us to reveal all line numbers simultaneously in Nano. Let's press ALT+N to display the line numbers in our test.sh script.

As a result, we observe the nano line numbers of the test.sh file presented in a column format on the left side of the window.

ALT+SHIFT+#

Similarly, the ALT+SHIFT+# shortcut key can be employed to switch the display of line numbers in Nano.

Consequently, we observe the line numbers in the same format activated by ALT+N. In essence, both shortcuts serve as synonyms for each other.

Using the -c Option

In addition to the shortcut keys, Nano offers various command-line options to maintain a consistent display of line numbers in a file. For example, the -c option, equivalent to --constantshow, ensures that line numbers remain visible throughout the editing session.

To implement this, we include the -c option in the Nano command to open the test.sh script:

$ sudo nano -c test.sh

Now, let's examine the outcome:

This is identical to starting nano with line numbers without flags and using the ALT+C key combination.

Using the -l Option

The -l option, abbreviated for --linenumbers, is an alternative command-line choice that instructs Nano to display line numbers in a column format.

$ sudo nano -l test.sh

🔗 Explore our comprehensive "Linux Commands Cheat Sheet" for quick reference and master your Linux skills! 🚀

To display the current line numbers while opening a file with nano, use the -c or --constantshow option:

nano -c filename

Here, nano doesn't show all line numbers on the left side by default. Instead, it dynamically displays the current line number information at the bottom of the editor as you navigate through different lines.

The cursor position info includes the row number (line number), and as you use the arrow keys to move the cursor to different lines, the line numbers at the bottom update accordingly. Essentially, you get real-time feedback of the current line number as you navigate within the nano editor.

🔗 "Want to learn more about Nano Jump to Line? Check out our comprehensive guide here!"

Show the current line number in nano using the shortcut

In nano with line numbers, you can quickly display the current line number by using the shortcut Ctrl+C. Pressing Ctrl+C will toggle the display at the bottom of the editor, showing the current cursor position information, including the line number. This allows you to check the line number as you navigate through different lines in the Nano editor.

Show current line number from within Nano editor

No need to fret if you forgot to open the file with the -c option. You can still achieve the same outcome from within the Nano editor, albeit with a slight inconvenience.

While viewing a file in Nano, simply press Ctrl+C, and it will reveal the current cursor position information at the bottom.

Unlike the earlier option, it won't continuously display the current line numbers as you navigate through lines. Instead, you'll need to press Ctrl+C each time you wish to check the current line number. I admit, not the most convenient approach.

Change Nano configuration to always show current line number at bottom

This essentially solidifies the initial approach, eliminating the need to open files with nano -c repeatedly. The decision to make this adjustment permanent is entirely yours. To do so, edit the nanorc file. If it doesn't exist, it will be generated.

nano ~/.nanorc

Add the following line:

set constantshow

If you later decide against it, edit the file again and remove the line that says `set constantshow`.

🚀 Ready to become a Nano ninja? Discover more essential Nano text editor tricks in our comprehensive guide on "How to Move End of the Line in Nano"! 📝💡

To permanently display line numbers in Nano, you can edit the nanorc configuration file. Follow these steps:

  1. Open or create the nanorc file:

nano ~/.nanorc

  1. Add the following line to enable line numbers:

set linenumbers

  1. Save the changes and exit Nano.

Every time you open Nano, it will display line numbers for each line by default. If you ever want to disable line numbers, you can edit the nanorc file again and remove the `set linenumbers` line.

Conclusion

You can easily set line numbers in your nano editor using 4 methods. Line numbers are important for users to get references on which line they are working on. Enabling them will help them understand and find an error in any lines. In this article, we have explained nano show line number commands. If you have any questions, you can ask them in the comment box.

Antoniy Yushkevych

Antoniy Yushkevych

Master of word when it comes to technology, internet and privacy. I'm also your usual guy that always aims for the best result and takes a skateboard to work. If you need me, you will find me at the office's Counter-Strike championships on Fridays or at a.yushkevych@monovm.com