There are two ways you can get to a specific line in the nano text editor:
- Open a file with a cursor at that specific line using
nano +n Filenamewhere the
nis the number of a line.
- If you've already opened the file with the nano editor, then press
Ctrl + /and enter the number of the line and it will land you on the entered line.
Want a detailed explanation? Here you have it.
Open a file to a specific line in the nano editor
This is what I personally use while debugging code as the error also points to the line where you made an error.
In simple terms, if you know on which line you want to make changes, this is what you should be using!
To use this method, you have to specify the number of a line while opening the file with the nano as shown:
nano +number_of_line Filename
For example, if I want to go to the 7th line in the
sample.sh file, then I will be using the following:
nano +7 sample.sh
I would recommend using the
-l flag which will add a number column to the left side indicating the line number:
nano -l +number_of_line Filename
Go to a specific line in the Nano editor
If you want to go to a specific line within the nano editor, then you can follow the given steps:
- Show the number of lines by pressing
Alt + #(optional but helpful).
Ctrl + /to open a prompt to enter the number of the line.
- Enter the number of the line and hit the
Still confused? Let me show you how to pull that off:
Pretty easy. Right?
More on the nano editor
If you are just getting started with the nano editor, you can refer to our beginner's guide to the nano editor:
I hope you will find this guide helpful.