Is there line numbering for nano?

Is there a way to turn on line numbering for nano?


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Adding set linenumbers in /etc/nanorc works for me in nano version 2.7.1.

It also can be activated with -l or --linenumbers on the command line.

Toggle the line numbers from within nano with: M-# in my case Alt+Shift+3.

Method 2

The only thing coming close to what you want is option to display your current cursor position. You activate it by using --constantshow (manpage: Constantly show the cursor position) option or by pressing AltC on an open text file.

Method 3

This was added on the 20th of October and was documented on the 22nd of October and has yet to make it into a release so compile it from source like so:

git clone git://;cd nano;./;./configure;sudo make install

Then add the following to your .nanorc:
set linenumbers

You can use ^# to turn line numbers on and off from within Nano. It’s probably a bit buggy since it’s recent and hasn’t been tested by many people.

Method 4

Nano is by design a very simple editor with few features. If you start wishing for anything beyond basic edition, nano isn’t the right tool. Emacs is a very powerful editor; to switch line numbers on, type M-x linum-mode. If Emacs scares you and you want a text mode editor, consider Joe, where line numbers are switched on with the -linums option.

That being said, line numbering was eventually added five years after this question was asked.

Method 5

It’s 2021. The OP’s question is still valid, but many of the answers here are for an older version of nano. I’m not presenting this answer as “the last word” – only as an update.

The default screen of nano consists of five areas. From top to bottom these are: the title bar, a blank line, the edit window, the status bar, and two help lines.

Where to display line numbers?

Line numbers may be displayed in one of two places:

  1. the edit window
  2. the status bar

The status bar display simply updates the line number (and column) of the cursor/insertion point as it’s moved about in the edit window. Line numbers in the edit window are positioned in the left margin. It is possible to display the line number in either or both the edit window and the status bar.

Display line numbers in the edit window:

There are several methods (this is not necessarily a complete list):

1. before the file is opened:

Edit/create the file ~/.nanorc with the following line:

set linenumbers

2. when the file is opened:

Use the -l option in nano:

$ nano -l <myfilename>

3. after the file is opened:

Toggle line numbers “on” and “off” w/ alt-shift-#:


Display line numbers in the status bar:

1. before the file is opened:

Edit/create the file ~/.nanorc with the following line:

set constantshow

2. when the file is opened:

Use the -c option in nano:

$ nano -c <myfilename>

3. after the file is opened:

Toggle line number display in the status bar “on” and “off” w/ alt-shift-C:



These all work as of today: Ubuntu 20.04, nano --version = GNU nano, version 4.8, although there are minor discrepancies in the documentation.

Method 6

Alternative, a quick alias in .bashrc:

echo "alias nano='nano -c -l'" >> ~/.bashrc && source ~/.bashrc && reset

Forcing the syntax seems mandatory for hashbang scripts, so to force a particular highlighting:
echo "alias nano='nano --syntax=php -c -l'" >> ~/.bashrc && source ~/.bashrc && reset

man nano

Method 7

For Mac users and nano 6.1 (the version is important) press EscN to toggle on/off line numbering on the edit window.

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments