The relative line number style in url below would be very useful for me.

How can I replicate Vim's code folding?

This package shows the number of current position, not just 0. Both sides of the current line shows relative numbers as usual. I like it.

Should I modify downloaded relative line numer package or is there any package which already supports this function?

1 Answer 1


I think those screenshots are actually of vim, in which case all you need to do is :set rnu.

For emacs, you're looking for linum-relative.

I have various hacks you might be interested, which makes the emulation of rnu closer:

(with-eval-after-load 'linum
  (set-face-background 'linum nil)

  (require 'linum-relative)

  ;; truncate current line to four digits
  (defun linum-relative (line-number)
    (let* ((diff1 (abs (- line-number linum-relative-last-pos)))
            (diff (if (minusp diff1)
                    (+ diff1 linum-relative-plusp-offset)))
            (current-p (= diff linum-relative-plusp-offset))
            (current-symbol (if (and linum-relative-current-symbol current-p)
                              (if (string= "" linum-relative-current-symbol)
                                (number-to-string (% line-number 1000))
                              (number-to-string diff)))
            (face (if current-p 'linum-relative-current-face 'linum)))
      (propertize (format linum-relative-format current-symbol) 'face face)))

    linum-relative-current-symbol ""
    linum-relative-format "%3s "
    linum-delay t)

  (set-face-attribute 'linum-relative-current-face nil
    :weight 'extra-bold
    :foreground nil
    :background nil
    :inherit '(hl-line default)))
  • Wow! This is great. This is exactly what I wanted. Thanks a lot. It works very well. Aug 21, 2015 at 5:18
  • Is most of this necessary? I just (setq linum-relative-current-symbol "") for the mode, and it works.
    – ergosys
    Apr 9, 2016 at 20:33
  • @ergosys I'm not sure it's strictly necessary, now that I think about it.
    – PythonNut
    Apr 9, 2016 at 20:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.