2

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?

cloudrain21
  • 121
  • 2

1 Answers1

3

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
                    (+ 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))
                                linum-relative-current-symbol)
                              (number-to-string diff)))
            (face (if current-p 'linum-relative-current-face 'linum)))
      (propertize (format linum-relative-format current-symbol) 'face face)))


  (setq
    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)))
PythonNut
  • 10,243
  • 2
  • 29
  • 75