Sublime Forum

Relative line numbers, because plugins can't properly do it

#22

+1
Would like to see this in ST too.

0 Likes

#23

I don’t usually like to +1 posts, but this would be a wonderful feature for sublime to support out of the box, with the option to have it on only for normal mode.

0 Likes

#24

What is the benefit of relative line numbers ?

1 Like

#25

If you use Vintage mode or are familiar with how Vim works, it’s for easily knowing how many lines away from your cursor another line is.

With Vim/Vintage, in “command mode” most of the keys on the keyboard are used for various forms of navigation, such as jumping forward or backwards a certain number of words, jumping into the next set of parentheses on the line, jumping up or down by a line, etc, but if you type a number before the navigation key it will make the jump that number of times. For operations that affect entire lines, such as delete, copy, select, replace, you can quickly apply the same operation to 15 lines by adding the number 15 before the command.

With relative line numbers, as you can see from the screenshots, the line numbers for all lines other than the cursor are numbers relative to the cursor’s position. This means that if you’re on line 285 and wanted to delete down to line 298, instead of seeing 298 in front of that line you would see 13, and immediately know that typing ‘d13j’ would delete all of the lines down to and including the one that starts with 13. This prevents you from having to do any math such as 298-285, or doing extra steps such as pressing v to enter selection mode, typing ‘298 SHIFT+G’ to jump the cursor to absolute line number 298, and then pressing the ‘d’ key to delete. It turns all of your multiline commands into single fluid keystrokes.

The most common example for me would be jumping somewhere on the page, copying or cutting a specific number of lines, then jumping somewhere else on the page and pasting them. With vim and relative line numbers to help you immediately know which numbers to type, performing that operation takes under 2 seconds and would look like this:
‘8k’ (jump up 8 lines to get the cursor in the right position),
‘d10j’ (delete from the cursor downwards for 10 lines),
‘5k’ (jump up 5 more lines to get to the new location where the code will go), and finally
‘p’ (to paste the most recently deleted text).

All of the numbers mentioned would either require counting line by line or doing math to come up with the correct number, but the relative line numbers plugin just shows them right on the screen! It really saves so much time once you become familiar with Vim navigation keys.

5 Likes

#26

Is there any update regarding this!?? I tried francescarpi/RelativeLineNumbers but it’s literally a phantom of a strip that goes away after 1 second. Not usable IMO (even with increasing timeout option, UX is not good) :frowning:

0 Likes

#27

Typing 5 j will move the cursor five lines down.

0 Likes

#28

Really interested in this as well, considering it already is a default choice in other editors like VS code.

0 Likes

#29

I’m watching this topic waiting for new replies :face_with_monocle:

0 Likes

#30

There is

	// relative_line_numbers will draw each line number as the distance from
	// the current line. Useful in conjunction with Vintage.
	"relative_line_numbers": false,

in ST 4

5 Likes

#31
0 Likes

#32

I just made a new little plugin for this: https://github.com/bicarlsen/vintage_relnums

It’s my first plugin, so would love suggestions on how to improve it.

0 Likes

#33

Yes, having the ability to write in different columns inside the gutter would be quite useful. Here is a link to the Sublime Text forum that discusses this idea in detail: https://forum.sublimetext.com/t/relative-line-numbers-in-the-style-of-vim/22920

0 Likes

#34

Sublime has supported relative line numbers natively since build 4107:

	// relative_line_numbers will draw each line number as the distance from
	// the current line. Useful in conjunction with Vintage.
	"relative_line_numbers": false,
0 Likes