Linux show number line

Is there line numbering for nano?

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 .

I like this but it should be noted that when you copy and paste multiple lines, the line numbers will also copy and paste.

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

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.

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:

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.

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).

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.

It’s 2021. The OP’s question is still valid, but many of the answers here are for an older version of nano . I’m not presenting this answer as «the last word» — only as an update.

The default screen of nano consists of five areas. From top to bottom these are: the title bar, a blank line, the edit window, the status bar, and two help lines.

Where to display line numbers?

Line numbers may be displayed in one of two places:

Читайте также:  Удалить node js linux mint

The status bar display simply updates the line number (and column) of the cursor/insertion point as it’s moved about in the edit window. Line numbers in the edit window are positioned in the left margin. It is possible to display the line number in either or both the edit window and the status bar.

Display line numbers in the edit window:

There are several methods (this is not necessarily a complete list):

1. before the file is opened:

Edit/create the file ~/.nanorc with the following line:

2. when the file is opened:

3. after the file is opened:

Toggle line numbers «on» and «off» w/ alt-shift-# :

Display line numbers in the status bar:

1. before the file is opened:

Edit/create the file ~/.nanorc with the following line:

2. when the file is opened:

3. after the file is opened:

Toggle line number display in the status bar «on» and «off» w/ alt-shift-C :

Summary

These all work as of today: Ubuntu 20.04, nano —version = GNU nano, version 4.8, although there are minor discrepancies in the documentation.

Источник

How to display line numbers in ‘less’ (GNU)

less is a linux command line utility, and is very commonly used by programmers to view text files. This question is solidly on-topic for Stack Overflow under the domain of «tools used by programmers» just as all questions relating to using git are on-topic. It is also the first hit in Google when searching for «less show line numbers.» This question should not be closed.

@JohnDibling The question is more appropriate for Unix & Linux Stack Exchange. Just because less is used by programmers does not make it on topic. Pencils are «tools used by programmers» too but a question about how to sharpen a pencil would not be appropriate here.

@augurar I think you DO know that tools here means software tools. You are deliberately interpreting the meaning of tools out of the context. By the way, I think as well that this question is appropriate for Unix & Linux Stack Exchange, but it does not prevent this question to be here on SO 🙂

6 Answers 6

-N or —LINE-NUMBERS Causes a line number to be displayed at the beginning of each line in the display.

You can also toggle line numbers without quitting less by typing -N .

It is possible to toggle any of less’s command line options in this way.

Читайте также:  Linux file execute permissions

When I less a huge file then «G» to the bottom, it says «Calculating line numbers. (interrupt to abort)» even though it is not displaying line numbers. I’d like to know how to find out what line I’m on without exiting and relaunching with -N. I’m suffering the penalty. Where’s the reward?

Hit ENTER/RETURN if you’re trying to toggle. After typing -n or -N while using less, you may also need to hit that afterwards to put the changes into effect. It even says so at the bottom, but my brain didn’t connect the dots because I assumed it would be instantaneous and I kept typing -N and was wondering why the numbers never showed up.

YES!! FYI: If you use -h from within less as guidance, it will lead you astray. It lists -n and -N as equivalent, but they are not. -N works, -n doesn’t. Is this a bug — or am I missing something?

@BrunoBronosky You can hit the = key at any time while in less, it will show you the line range currently being displayed plus the total size (available for files, not streams) like this at the bottom: «Filename.txt lines 1-50/300 byte 4021/26976 15% (press RETURN)»

You can also press = while less is open to just display (at the bottom of the screen) information about the current screen, including line numbers, with format:

myfile.txt lines 20530-20585/1816468 byte 1098945/116097872 1% (press RETURN) 

So here for example, the screen was currently showing lines 20530-20585 , and the files has a total of 1816468 lines.

You could filter the file through cat -n before piping to less :

Or, if your version of less supports it, the -N option:

You can set an enviroment variable to always have these options apply to all less’d file:

The options are: R = better handling of raw color codes in files. S = Scroll long lines off the screen instead of word wrap. #3 = scroll right/left by 3 positions at a time. N = show line numbers. M = Longer prompts. ~ = Instead of displaying empty space after a file ends with ~, display nothing for blank space. g = when doing a search with ‘g’, only highlight the current match instead of all matches.

I guess by aliasing the commands that have the trouble, or more simply less to set the variable only for each of its invocations.

The command line flags -N or —LINE-NUMBERS causes a line number to be displayed at the beginning of each line in the display.

You can also toggle line numbers without quitting less by typing -N . It it possible to toggle any of less ‘s command line options in this way.

Passing -N or —LINE-NUMBERS only shows the date for me in CentOS 5.3. However using -N after starting less works fine.

Читайте также:  Cbl mariner linux iso

If you hit = and expect to see line numbers, but only see byte counts, then line numbers are turned off. Hit -n to turn them on, and make sure $LESS doesn’t include ‘n’.

Turning off line numbers by default (for example, setting LESS=n ) speeds up searches in very large files. It is handy if you frequently search through big files, but don’t usually care which line you’re on.

I typically run with LESS=RSXin (escape codes enabled, long lines chopped, don’t clear the screen on exit, ignore case on all lower case searches, and no line number counting by default) and only use -n or -S from inside less as needed.

Источник

How to Show Line Numbers in Nano Editor?

Do you wish you had Nano line numbers? Well, now you can; read on to find out how to show line numbers in Nano editor.

How to Show Line Numbers in Nano Editor?

List of content you will read in this article:

The nano editor is a text editor included in many Unix-based systems. It is a small, lightweight editor that is easy to use and perfect for making simple changes to text files. If you’re new to the nano text editor, you may wonder how to show line numbers in Nano. This can be helpful when working with long files or finding a specific line of code.

How to Show Line Numbers in Nano? [Nano Line Numbers]

There are 4 methods to show line numbers in nano, and they are as follows:

Method 1:

You can directly use the following command to display line numbers in Nano:

nano —linenumbers [filename]

nano —linenumbers testfile.txt

Method 2:

You can press Alt +Shift + 3 key combinations to display line numbers quickly.

Method 3:

You can compile Nano from scratch:

git clone git://git.savannah.gnu.org/nano.git;cd nano;./autogen.sh;./configure;sudo make install

Then, in your /.nanorc file, add the following codes, do not worry if this file is empty. This file is not existed by default:

# include all the preexisting configs
include «/usr/share/nano/*.nanorc»
set linenumbers

Method 4:

You can use CTRL + C to display the current line number.

Also, to display the line & column number, you could just add the -c parameter when running nano editor:

Conclusion

You can easily set line numbers in your nano editor using 4 methods. Line numbers are important for users to get references on which line they are working on. Enabling them will help them understand and find an error in any lines. In this article, we have explained nano show line numbers commands. If you have any questions, you can ask them in the comment box.

People are also reading:

Источник

Оцените статью
Adblock
detector