10

I find both number and relativenumber useful. Is there any way to display them both at the same time?

5
  • 5
    Other than using set number relativenumber ?
    – VanLaser
    Dec 2, 2015 at 10:11
  • That shows me only the relativenumber, not the absolute one. Dec 2, 2015 at 11:34
  • 1
    On a different machine, it shows me the only the absolute number of the current line, and all the relative numbers. I want them both at the same time Dec 2, 2015 at 11:36
  • I think the OP wants the option to show relative numbers and and absolute numbers in the number column at the same time. AFAIK, that isn't possible. Dec 2, 2015 at 12:29
  • Yes, it's possible by using additional plugins (as in the answer by @christian-brabandt) -- see stackoverflow.com/a/16624418 Sep 26, 2018 at 20:25

4 Answers 4

8

Showing all the line numbers and relative numbers at the same time isn't possible. But you can get the current line number and the relative number for all the others. From :help number_relativenumber:

The 'relativenumber' option changes the displayed number to be
relative to the cursor.  Together with 'number' there are these
four combinations (cursor in line 3):

    'nonu'          'nu'            'nonu'          'nu'
    'nornu'         'nornu'         'rnu'           'rnu'

    |apple          |  1 apple      |  2 apple      |  2 apple
    |pear           |  2 pear       |  1 pear       |  1 pear
    |nobody         |  3 nobody     |  0 nobody     |3   nobody
    |there          |  4 there      |  1 there      |  1 there

The reasoning about this can be found at this discussion on vim-dev mailing group, which contains a link to a similar reddit question: Relative numbering with absolute number on the current line.

6

It is not really possible to have both number and relativenumber displayed at the same time, besides what is mentioned at :h number_relativenumber (see different answer).

However, you can misuse the gutter column to display extra numbers. For example, you can use my DynamicSigns plugin and let it draw the relativenumber column besides the number column. For that to work, you do something like this:

 :SignExpression CustomSignExpression(v:lnum, 1)
 :let &nuw=&nuw+1
 :set nu

See the help :h SignExpression for the definition of the CustomSignExpression function (The 1 means, to draw the relativenumber at every line, use 5 to draw it only every fifth line). Increasing the 'numberwidth' setting (the :let &nuw=&nuw+1 part) just makes sure, there will be an extra space between the gutter column and the number column.

Note however, this will considerable slow down vim when scrolling, as the signs need to be recreated on every move.

See this example. enter image description here

1

Yes. Install RltvNmbr plugin. As you can see, I have two number columns. Frist is relative.

enter image description here

1

This bit of my vimrc comes close to what you want:

set number             " Enable line numbering
augroup numbertoggle   " Toggles relativenumber on and off based on mode
    autocmd!
    autocmd BufEnter,FocusGained,InsertLeave * set relativenumber
    autocmd BufLeave,FocusLost,InsertEnter   * set norelativenumber
augroup END

It turns on relative line numbering while in normal mode (where it's useful) and absolute line numbering while in insert mode.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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