Type 0 to show relative line numbers for the next command

How about 0 to show line numbers relative to the main cursor line for the next command?

Highlighter

add-highlighter window/number-lines number-lines -relative

Example – Jump down 6 lines:

06j
1 Like

06j already works :smiley: I suspect you meant 06g but as you can see its redundant with 6j, so this is not a really strong motivating use case in my book.

I think you’ve misunderstood the point. When using relative line numbers it is extremely easy to move by several lines down or up with j and k because you can see how many lines you need to jump. What @alexherbo2 wanted is to enable relative line numbers for next movement when 0 is pressed. For example:

433|
434|
435| some text█
436|
437|
...
452| needed text

We have such buffer, and we need to go to line 452 really quick. Our options are: 452g - 4 keys, jjjjjjjjjjjjjjjjj - 17 keys, or we could type 17j which is 3 keys, but we need to calculate 17. By pressing 0 we turning on relative line numbers:

  2|
  1|
435| some text█
  1|
  2|
 ...
 17| needed text

And we can immediately see that we need to press 17j, so this is 4 keys in total: 017j. And then we have our normal line numbers back. Though I use relative line numbers all the time.

This also can be applied to C, e.g: 07C will place cursors on each line without the need of always on relative line numbers

2 Likes

My issue with relative line numbers is they draw many attention to be enabled all the time. I’m exploring a setting which could work for me, with number-lines -relative enabled for a single command. I guess the general issue to this is the count argument before the command. It’s similar to 1s{regex-with-capture}<ret>, I usually think the capture when building the regex, and not before. The command works incrementally, but it’s not that incremental if in my head I have to think the argument before. xD

def switch-number-line -params .. %{
    try %{ remove-highlighter window/number_lines }
    add-highlighter window/number_lines number-lines %arg{@}
}

hook global NormalKey 0 'switch-number-line -relative'
hook global NormalKey \D.* 'switch-number-line'
1 Like