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.

4 Likes