I find both number and relativenumber useful. Is there any way to display them both at the same time?
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
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.
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.