I installed linum relative with this. But installing this replaced my fixed linum. I want to have both fixed line number and relative line number as well. How can I do this?
(require 'linum) (add-hook 'prog-mode-hook 'linum-mode) (defvar my-linum-format-string "%3d") (add-hook 'linum-before-numbering-hook 'my-linum-get-format-string) (defun my-linum-get-format-string () (let* ((width (1+ (length (number-to-string (count-lines (point-min) (point-max)))))) (format (concat "%d (%" (number-to-string width) "d)"))) (setq my-linum-format-string format))) (defvar my-linum-current-line-number 0) (setq linum-format 'my-linum-relative-line-numbers) (defun my-linum-relative-line-numbers (line-number) (let ((offset (- line-number my-linum-current-line-number)) (current (line-number-at-pos))) (propertize (format my-linum-format-string current offset) 'face 'linum))) (defadvice linum-update (around my-linum-update) (let ((my-linum-current-line-number (line-number-at-pos))) ad-do-it)) (ad-activate 'linum-update)
It will show in the right column the absolute number of the line and in parenthesis the relative number in regard to the current line.
izkons's comment above seems like an answer to me...
I just use https://github.com/scottjad/linum-relativenumber which does it all. – izkon
Some caveat's about this solution:
- This modifies
linumsettings so might not respect customizations
- This might require a restart or a bunch of fiddling to
switch offdisable relative line numbers while keeping absolute line numbers.
Do you want to have them both running? Toggle?
You can try this package https://github.com/coldnew/linum-relative
And then I think you can toggle it