How to set relative line numbers in Doom Emacs
Asked Answered
C

2

12

I know that you can toggle line numbers with the key combination SPC + t + l but it changes back to absolute line numbers when restarting Doom Emacs. How can I configure Doom Emacs to set relative line numbers every time I start emacs?

Caresa answered 10/8, 2019 at 5:15 Comment(1)
You have to customize display-line-numbers-type: (setq display-line-numbers-type 'relative) inside your init.el.Immeasurable
T
13

As of commit a7da9a4 doom-line-numbers-style has been removed. The correct way of setting line number type is to set the display-line-numbers-type variable. This is part of Emacs itself and as such will work outside of doom too.

To answer op's question, the way to set line numbering to be relative is to add the following snippet to your configuration file which in the case of doom is ~/.doom.d/config.el.

(setq display-line-numbers-type 'relative)
Trochilus answered 9/7, 2020 at 22:17 Comment(0)
P
8

Assuming on latest version, which is v2.0.9 at the time of writing, the preferred way would be to set the doom-line-numbers-style to 'relative in your own private config. Simply add (setq doom-line-numbers-style 'relative) to that config. This will configure emacs to start with relative line numbering.

Note however that toggling line numbers with SPC t l will still change it back to absolute line numbering. To toggle relative line numbering, you need to provide a universal argument to the toggle command. In this case, you'd have to do SPC u SPC t l. The SPC u there stands for the universal/prefix argument.

Peloquin answered 30/8, 2019 at 18:42 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.