Display line numbers in nano text editor

We would cover how to display line numbers in nano text editor in this article. nano is a text editor. It is one of the easiest text editors to use in Linux. In previous article, we discussed Editing files with nano. If you have just started then do follow Editing files with nano article.

So, nano by default doesn’t display line numbers. Though it has a feature through which we can go to a specific line number. But, why do we need to see line numbers in the first place? Let’s say we have thousand lines of code. And, if know what code to edit at a specific line number then, we don’t have to search for that particular instruction set again and again. It only increases our productivity.

Just consider it like a bookmark in book. With a bookmark we know from where we have to resume reading our book. Otherwise, we would waste time just flipping the pages.

Now, we first discuss how to display line numbers and thereafter how to quickly go to specific line.

Display line numbers in nano text editor

To display line numbers when we open a file, use –linenumbers option.

nano --linenumbers <file_name>

For instance,

nano --linenumbers test.txt

where, test.txt is a text file we want to edit.

Go to a line in nano

Once, we have identified the content present on a specific line number. Then, either we can use Page Down or Page Up key. Or, we can use a key combination to reach to a specific line. Use the key combination –

Ctrl + /

It will prompt us for a line number to enter. Once we provide the line number and press Enter. It will take the cursor to that particular line.

In conclusion, we covered how to reach a specific line in nano here. Also, we saw how to display line numbers.

Similar Posts