One of the new features in Emacs 26 is display-line-numbers-mode:

Emacs now supports optional display of line numbers in the buffer.
This is similar to what linum-mode provides, but much faster and
doesn't usurp the display margin for the line numbers.  Customize the
buffer-local variable 'display-line-numbers' to activate this optional
display.  Alternatively, you can use the `display-line-numbers-mode'
minor mode or the global `global-display-line-numbers-mode'.  When
using these modes, customize `display-line-numbers-type' with the same
value as you would use with `display-line-numbers'.

Up to now, I've been using linum-relativenumber to get both relative and absolute line numbers at the same time. Here is how it looks:

Now that the new display-line-numbers-mode feature is here, with promises to be much faster, I thought maybe I could switch to using that instead.

But I haven't been able to figure out how to get it to show both relative and absolute line numbers, since the help for display-line-numbers-type points to display-line-number, which says:

Non-nil means display line numbers.
If the value is t, display the absolute number of each line of a buffer
shown in a window.  Absolute line numbers count from the beginning of
the current narrowing, or from buffer beginning.  If the value is
‘relative’, display for each line not containing the window’s point its
relative number instead, i.e. the number of the line relative to the
line showing the window’s point.

and there doesn't seem to be a both setting.

Can anyone suggest a way to get both relative and abolute line numbers using the new display-line-numbers-mode feature?

  • Do the proposed settings in this comment of mine result in the desired behaviour?
    – Basil
    Oct 14 '17 at 1:16
  • Thank you, but that doesn't do quite what I want. It shows the absolute line number of the current line and relative line numbers of the rest, but I want to see both the relative and absolute line numbers of every line (in two columns, right next to each other). Here is how I'd like it to look (which is how it does look with linum-mode when using the linum-relativenumber package, but I'd like to do it with the native Emacs 26 display-line-numbers-mode instead.
    – izkon
    Oct 14 '17 at 1:39
  • Ah, native line numbers can't do this on their own, but since they are in-buffer, leaving the margin/fringe free, you can enable them at the same time as other packages, e.g. nlinum or similar.
    – Basil
    Oct 14 '17 at 1:43
  • Since this thread is related to emacs.stackexchange.com/questions/29325/…, I wanted to post a comment joining the two.
    – lawlist
    Oct 14 '17 at 5:27

Your Answer

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

Browse other questions tagged or ask your own question.