Relative Line Numbers in Emacs

Oh, line numbers. It’s one of the surprising joys of writing in a text editor. But many writers ignore line numbers. I understand. We think in sentences and paragraphs.

But, as I argued in a previous article about writing one sentence per line, you can (and should) think in lines. There are certainly benefits to this approach, and I mentioned flipping a certain variable in Emacs for relative line numbers.

Let’s learn how to do that now.

What Are Relative Line Numbers?

Before we get into the why and how it’s important that you understand what relative line numbers are.

By default, your text editor likely displays absolute line numbers. It starts at the top with line 1 and goes down to whatever. But with relative line numbers, your current line is 0, and the text editor counts up in either direction. You can see in the image below, that I’m currently on line 17, and we have 1s on either side.

Benefits of Measuring Lines

This is good for writers who want to measure lines. As I mentioned, writing one sentence per line is a great way to quickly see how many sentences you have in a paragraph.

(If poets get this granular, why not prose writers? No, seriously.)

Also, you’re working on a computer. So you’re not literally “measuring” or counting lines one by one. The computer is calculating it for you.

How To Enable Relative Line Numbers

You can accomplish the magic relative line numbers trick by turning on the variable display-line-numbers.

M-x customize-variable

Choose the variable: display-line-numbers.

Set the value to Relative line numbers:

For those who like to set variables with Emacs lisp, you can do it this way:

(setq display-line-numbers 'relative)

Well done! You just executed this article perfectly. And the benefits have been installed in your brain.

As always, if you have any comments or questions feel free to leave them below, and I will do my best to answer.

🕶 Yes!

Sign up to get an occasional email from me with the content you crave.

We’ll never send you spam or share your email address.
Find out more in our [link]Privacy Policy[/link].

Be the first to comment

Leave a Reply

Your email address will not be published.


*