3

I've turned on vim's relative line numbers, it starts from 0 but doing somthing like 10dd means I only get up to line 9, leaving the last one behind (becuase it's 10 including the current line). Yes, I know, It's only a super simple equation (10 + 1) but it's time taken up when I just want to check the number in the gutter and instantly get the number.

Is there a way to change the number the relative numbers start on? From 0 to 1? I've googled but I can't find anything and I did check out VIM's help page on the 'relativenumber' and 'number_relativenumber' sections but I couldn't see anything on it (or I probably missed it if it's there).

So is there any way to do this or is just not possible?

  • 1
    If you do d10 it behaves in a way that is consistent with relativenumber. This is also true for y10 and others. I believe these are the commands that devoloper of relative number had in mind. Not really an answer to your question but it might help you. – Tumbler41 Mar 1 '17 at 22:08
  • I know but becuase I see 10 as the line number I want to delete up to that's what I type in, if the line numbers started from 1, I would see 11 and type that in instead. Seeing 10 but needing to type in 11 to target that line just seems unintuitive to me. – Thermatix Mar 1 '17 at 22:14
  • I'ts not unintuitive if you use the other form. If it says 10 and you type in d10 you'll delete those 10 lines plus the one you're on. But I suppose if you're used to the other form this could still be annoying. – Tumbler41 Mar 1 '17 at 22:17
  • Typing in d10 to get relative line number 10 doesn't delete 10 lines plus the current one, it deletes 10 lines including the current one (up to relative line number 9), meaning you have to type d11 to get to relative line number of 10; so yeah, unintuitive. – Thermatix Mar 1 '17 at 22:26
  • generally not possible to do what you want. – Christian Brabandt Mar 2 '17 at 6:55
3

Well, vim is open source. If you clone it from:

git clone https://github.com/vim/vim.git

You can make the following changes to src/screen.c to do what you want:

diff --git a/src/screen.c b/src/screen.c
index 20a778a68..38d4368a9 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -2521,8 +2521,8 @@ fold_line(
        else
        {
        /* 'relativenumber', don't use negative numbers */
-       num = labs((long)get_cursor_rel_lnum(wp, lnum));
-       if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
+       num = labs((long)get_cursor_rel_lnum(wp, lnum)) + 1;
+       if (num == 1 && wp->w_p_nu && wp->w_p_rnu)
        {
            /* 'number' + 'relativenumber': cursor line shows absolute
             * line number */
@@ -3745,8 +3745,8 @@ win_line(
            else
            {
                /* 'relativenumber', don't use negative numbers */
-               num = labs((long)get_cursor_rel_lnum(wp, lnum));
-               if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
+               num = labs((long)get_cursor_rel_lnum(wp, lnum)) + 1;
+               if (num == 1 && wp->w_p_nu && wp->w_p_rnu)
                {
                /* 'number' + 'relativenumber' */
                num = lnum;

But sorry, examining the source confirms there's no existing option available to do what you want.

  • Thanks, some one else already mentioned that it just isn't possible to do what I want, but I might just look into forking and creating a PR to add this feature. I'll accept this as the answer as it gets me closest to what I want. – Thermatix Mar 3 '17 at 0:24
  • 1
    Wll, I told you so. – Christian Brabandt Mar 3 '17 at 6:56
1

You seem to be confusing ranges with counts.

d, y c, etc, take counts, not ranges, so will not work the way you expect.

Commands that take a range, such as :substitute, will work with relative line numbering, the way you seem to want. For example, :.,+10s/^/1 / will insert a 1 at the beginning of the current line, and the next 10 lines, inclusive.

To change the start number for relative line numbering would cause problems with using them to calculate ranges.

However, after additional testing, I've solved your real problem:

To delete from the current line, to relative line 10, the command you would use is d10j, 'd'elete, from the current line, for a count of '10', in the direction of 'j', or down.

  • I think you do not quite understand what I'm asking, I'm just asking if I can make relative line numbers start from 1 instead of 0, but apparently it's not possible. – Thermatix Mar 2 '17 at 10:42
  • Seeing 10 as the line # you want to delete up to is treating the 10 as a range, instead of the count that it is. – Herb Wolfe Mar 2 '17 at 12:18
  • Doesn't change the fact that I want to do is change relative line numbers to start from 1 instead of 0 and that according to a comment from @Christian Brabandt it's not possible. – Thermatix Mar 2 '17 at 12:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.