Want to display the line numbers in Nano while working on a text file?
There are two main ways for it:
- Display current line number at the bottom
- Display all line numbers at the left side
Here are the keys and commands for both methods:
|nano -c file||Opens file with numbers displayed at bottom for current line|
|Ctrl+C||Same behavior as above but from inside the editor|
|set constantshow||Add it to ~/.nanorc to make the above behavior permanent|
|nano -l file||Opens file with all line numbers displayed in left sidebar|
|Alt+# or Alt+Shift+3||Same behavior as above but from inside the editor|
|set linenumbers||Add it to ~/.nanorc to make the above behavior permanent|
If you always want to display line numbers in the left sidebar, you can make
Alt+# kind of change permanent by adding
set linenumber to the
Don't worry. I'll show all the steps in details.
Display current line number in Nano
--constantshow while opening a file with nano:
nano -c filename
Just to be clear, it won't display all line numbers by default in the left-hand side.
Instead, it displays the current line number information at the bottom as you move the cursor over different lines. Actually, it displays the cursor position info and row number (line number) info is one of them.
As you move the cursor (using arrow keys) and go to other lines, the line numbers change as well. Basically, you continuously see the current line number at the bottom of the nano editor.
Show current line number from within Nano editor
If you forgot to open a file with the
-c option, no worries. What you see above can also be achieved from within the editor but with a little problem.
When you are viewing a file with Nano, press
Ctrl+C and it will display the current cursor position information at the bottom.
You have to press Ctrl+C each time you want to see the current line number. Not very convenient, I know.
Change Nano configuration to always show current line number at bottom
This is simply making the first method permanent. This way, you don't have to open a file with
nano -c every time.
It is up to you if you want to make this change permanent.
Edit the nanorc file. If it doesn't exit, it will be created.
And add the following like to it:
If you would rather not want it, edit the file again and remove the
set constantshow line.
Display all the line numbers in left side in Nano editor
Open a file with
-l option to display all line numbers in the left side:
nano -l filename
And you should see the line numbers now:
While using the nano editor, you can use the modifier key and have the line numbers displayed on the left side all the time.
For Linux distributions, it should be
Alt+# keys. If your keyboard does not have the # key, you can use
Alt+shift+3 to achieve this.
On macOS, the modified key is
Esc so use
You can make this behavior default by adding the following line to your
As you can see, it is not a lot different than showing line numbers in Vim. Good to see such option available that make Nano an excellent choice.