Better Line Numbering in emacs

gga

Earlier this year while pairing with Julio Maia, an unashamed vim user, I noticed that the line numbers didn’t count from the top of the file in his editor. Instead, all line numbering was relative to his current line. It looked something like this.

This was really cool. It’s really easy to navigate and edit when you can see how many lines to move without having to count. It also didn’t hurt pairing. I could just refer to something ‘there, on line -10.’ I had to have it. So I hacked it into the linum.el mode that comes with my editor of choice, emacs.

Now that I’m reading Avdi Grimm’s emacs reboot, including his article about line numbering, I thought I should share. At least until I can get this submitted back upstream.

In your linum.el file, add the following after all the existing defcustom forms.

(defcustom linum-offset nil
"Whether line numbers should be an offset from point or absolute within the buffer."
:group 'linum
:type 'boolean)

And then replace the existing linum-update-window function with the following.