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.

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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