13

Is it possible to show the absolute number of the current line, instead of "0", when in relative line number mode? This is sometimes referred to as "hybrid line number mode".

Like this:

 7                                                                                                      
  6          this.oscs[i].oscillator.start();                                                            
  5        }                                                                                             
  4                                                                                                      
  3        this.bindController();                                                                        
  2      };                                                                                              
  1                                                                                                      
252      factory.stop = function () {  <- current line number shows                                                                                       
  1        console.log('theremin: now in stop 2');                                                       
  2        this.leapController.disconnect();                                                             
  3        //this.leapController.removeListener('frame', factory.ctrlFrameHandler);                      
  4        //this.leapController.removeListener('frame', this.ctrlFrameHandler);                         
  5        this.leapController.removeListener('frame', this.leapController.listeners('frame')[0]); 

Here's how you do it in vim.

I am running evil, and activate relative line number mode in my .emacs like so:

(linum-mode)
(linum-relative-global-mode)

I don't see any packages for this, or any customization available for it in the existing packages. I'm somewhat familiar with elisp, so it might be possible to figure out how to hook the existing code e.g with advice, but I'd rather avoid going that route if possible.

Many Thanks.

5
  • linum-relative-global-mode is provided by evil ?
    – phils
    Commented Jan 14, 2016 at 10:32
  • no, it's part of the standard emacs package 'linenum-relative'. Running evil probably has nothing to do with this question, other than the fact that relative line numbers are most likely to be useful to 'vi users' i.e people running evil. I'd just thought I'd mention it in case it's somehow relevant.
    – vt5491
    Commented Jan 14, 2016 at 10:56
  • No such package (nor "linum-relative") in the standard repo, and not a default library. Did you maybe mean one of the non-standard package repos? You should always be specific about any non-standard libraries you're referring to.
    – phils
    Commented Jan 14, 2016 at 11:26
  • github.com/coldnew/linum-relative . By 'standard' I didn't mean to imply part of the emacs base, but just a "standard" e.g "ordinary" package under melpa. And I yes, I did misspell it -- it 'linum-relative' not 'linenum-relative'. Sorry for the confusion.
    – vt5491
    Commented Jan 14, 2016 at 11:35
  • 1
    FWIW, Emacs 26 brings native (read: fast) line numbering, which can be hybrid if you set display-line-numbers to relative and display-line-numbers-current-absolute to t (the default).
    – Basil
    Commented Oct 13, 2017 at 20:19

2 Answers 2

11

You can make the current line number show instead of "0" by customizing the linum-relative-current-symbol variable.

You can change that variable by one of multiple ways.

  • M-x customize-group RET linum-relative RET

    From there, customize the "Linum Relative Current Symbol" variable (whose default value is 0). If you hit on the "More" link, below it, the full description of the variable will read:

    The symbol you want to show on the current line, by default it is 0.

    You can use any string like "->". If this variable is empty string, linum-relative will show the real line number at current line.

    So, set that value to empty string, simply delete that 0 and hit "Apply and Save".

  • Another way is to do add the below to your emacs config and evaluating it:

    (setq linum-relative-current-symbol "")
    
1

I'm running spacemacs and M-x linum-relative-mode does this exactly.

You can also add:

(setq-default dotspacemacs-line-numbers 'relative)

to the dotspacemacs/user-config function in .spacemacs to set line numbers in this style permanently.

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.