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


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

  • 4
    Good answer. The --const argument is the same as -c. Use it to open the file like this: nano -c filename . Also, to make it permanent, include the 'set const' option in your ~/.nanorc file, which may not exist until you create it. – MountainX Feb 2 '12 at 2:24
  • If your nano is newer, you may see the following in your man pages. -c, --constantshow Constantly show the cursor position on the status bar. Note that this overrides option -U (--quickblank). – Jay Bose Jul 30 '18 at 20:53

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.

  • Thanks for Alt+Shift+3 for toggling. – bob Jan 4 at 2:51
  • In addition to change the background color of the line numbers, I use set numbercolor ,normal – smac89 Apr 5 at 22:24

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://git.savannah.gnu.org/nano.git;cd nano;./autogen.sh;./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.

  • A good answer would have pointed out that the feature was added within the past day, and has no user experience to relate to. – Thomas Dickey Oct 22 '16 at 19:03
  • What do you mean by "has no user experience to relate to"? – faissaloo Oct 22 '16 at 21:57
  • 1
    There cannot be more than 1-2 users of the feature at this point in time, there are no bug reports. By the way, "recently" demands a date (or link to the commit making the change). – Thomas Dickey Oct 22 '16 at 22:06
  • I don't see how that is in any way related to the question. – faissaloo Oct 23 '16 at 8:02
  • 1
    You got the date wrong (see commit October 20 by Faissal Bensefia). It also was undocumented until mid-day October 22. All other points raised are still issues. – Thomas Dickey Oct 23 '16 at 10:18

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.

  • So.. Emacs is your text editor of choice? – Pacerier Aug 9 '16 at 14:33

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.