Manoj Rao bio photo

Manoj Rao

Your Average Common Man

Email Twitter Github

I use both vim and Emacs because I grew up using a lot of vim then decided to switch over to Emacs one day. The obvious choice was to switch to using Evil Mode. This post is not about that, at least not entirely. One of the things I missed dearly about vim was the ease with which you could use line numbers to move around and edit. I always found C-u preface very crufty. The implicit numeric argument that precedes a command is what makes you super fast with navigation in vim. However, I had come to like love Emacs to go back. So I copied took inspiration and wrote some ELisp code from the Internet and modified it to achieve the exact result I wanted. This is something that works out of the box on my Emacs - 26.1


Relative Line Numbers


Throw this in your .emacs and watch the magic!

(defvar my-linum-current-line-number 0)

(setq linum-format 'my-linum-relative-line-numbers)

(defun my-linum-relative-line-numbers (line-number)
  (let ((test2 (- line-number my-linum-current-line-number)))
     (number-to-string (cond ((<= test2 0) (* -1 test2))
                             ((> test2 0) test2)))
     'face 'linum)))

(defadvice linum-update (around my-linum-update)
  (let ((my-linum-current-line-number (line-number-at-pos)))
(ad-activate 'linum-update)

(global-linum-mode t)

Bring Your Own Cause

If you think any info here has remotely helped you consider dropping a penny for this cause, just click me . You can visit Unfortunately, there are plenty of sad things happening all over the world, if you have a different cause or charity you'd rather support please do. And if you did make a donation, please drop a note to me (annotated) or leave a comment here (anonymous is OK!) and I will use that as motivation to write more useful content here.

If you like topics such as this then please consider subscribing to my podcast. I talk to some of the stalwarts in tech and ask them what their favorite productivity hacks are:

Available on iTunes Podcast

Visit Void Star Podcast’s page on iTunes Podcast Portal. Please Click ‘Subscribe’, leave a comment.

Get it iTunes