Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set relative line numbers in Doom Emacs

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?

like image 392
n1ks Avatar asked Aug 10 '19 05:08

n1ks


People also ask

How do I add line numbers in Emacs?

By default, Emacs displays the current line number of the point in the mode line. You can toggle this feature off or on with the command M-x line-number-mode , or by setting the variable line-number-mode .

What is doom Emacs?

Doom is a configuration framework for GNU Emacs tailored for Emacs bankruptcy veterans who want less framework in their frameworks, a modicum of stability (and reproducibility) from their package manager, and the performance of a hand rolled config (or better).


2 Answers

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)
like image 67
fossegrim Avatar answered Nov 04 '22 20:11

fossegrim


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.

like image 29
alvinfrancis Avatar answered Nov 04 '22 19:11

alvinfrancis