5

I know this plugin for relative numbers, which works fine (with the option (global-relative-line-numbers-mode). I also know this elisp code, which gives me perfectly working absolute numbers:

(add-hook 'find-file-hook (lambda () (linum-mode 1)))

However, i don't know how i can have absolute line numbers on the current and relative line numbers on all other lines (both on the left margin like displayed in the picture below).

this picture of my vim This picute of my vim shows what i want. Therefore, i don't search for line numbers in the mode line.

Gracjan Polak
  • 1,082
  • 6
  • 21
toogley
  • 303
  • 2
  • 15

1 Answers1

5

If you're using relative-line-numbers-mode, you can customize the formatting to get what you want:

(defun relative-abs-line-numbers-format (offset)
  "The default formatting function.
Return the absolute value of OFFSET, converted to string."
  (if (= 0 offset)
      (number-to-string (line-number-at-pos))
    (number-to-string (abs offset))))

(setq relative-line-numbers-format 'relative-abs-line-numbers-format)

This format will then apply to any buffers in relative-line-number-mode.

Tyler
  • 21,719
  • 1
  • 52
  • 92
  • When i put that into my emacs init file and restart, nothing happens. Neither absolute, nor relative line numbers are visible. – toogley Apr 05 '16 at 17:16
  • woops. This assumes you're using `relative-line-numbers mode` already. I'll update – Tyler Apr 05 '16 at 17:17