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:

  6          this.oscs[i].oscillator.start();                                                            
  5        }                                                                                             
  3        this.bindController();                                                                        
  2      };                                                                                              
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:


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.

  • linum-relative-global-mode is provided by evil ? – phils Jan 14 '16 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 Jan 14 '16 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 Jan 14 '16 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 Jan 14 '16 at 11:35
  • 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 Oct 13 '17 at 20:19

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 "")
| improve this answer | |

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.

| improve this answer | |

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.