Ubuntu – How to show line numbering in nano when opening a file


Is there a way to tell nano to automatically show line numbering each time I open a file?

Best Answer

According to the man page for GNU nano 2.9.3, you can use the -l or --linenumbers flags.

       -l, --linenumbers
              Display line numbers to the left of the text area.

Alternatively, according to the man page for nanorc, you can add set linenumbers in ~/.nanorc, $XDG_CONFIG_HOME/nano/nanorc or ~/.config/nano/nanorc.

       nano will read two configuration files: first the system's  nanorc  (if
       it exists), and then the user's nanorc (if it exists), either ~/.nanorc
       or $XDG_CONFIG_HOME/nano/nanorc or ~/.config/nano/nanorc, whichever  is
       encountered  first.  See nanorc(5) for more information on the possible
       contents of those files.
       set linenumbers
          Display line numbers to the left of the text area.


In response to comments about alternate config files, from the description of man nanorc:

During startup, nano  will  first
       read  the system-wide settings, from /etc/nanorc (the exact path might be different on your
       system), and then the user-specific settings,  either  from  ~/.nanorc  or  from  $XDG_CON‐
       FIG_HOME/nano/nanorc or from ~/.config/nano/nanorc, whichever is encountered first.

I would not typically advise others to change the system-wide config file, unless you have a good reason to do so, as it will likely be overwritten during any updates, and is not likely to be included in system backups, which typically only include the home directory.