Emacs: Display Line Numbers
emacs has 2 line numbers mode.
linum-mode→ old, hack, slow. Emacs 23 (released in ).
global-display-line-numbers-mode→ Emacs 26 (beta as of 2017-07-25)
Emacs 26 (beta as of 2017-07-25) has a new line number mode.
Put this in your emacs init file:
(when (version<= "26.0.50" emacs-version ) (global-display-line-numbers-mode))
display-line-numbers-mode is written by Eli Zaretskii. Thanks Eli.
Emacs 23 (released in ) has a line number mode. It shows line numbers in margin. [see Emacs 23.1 New Features (released 2009-07)]
To toggle it in current buffer, Alt+x
To toggle globally, Alt+x
To set it permanetnly, put this in your emacs init:
(global-linum-mode 1) ; always show line numbers
How to set line number to start at 0?
If you want line number to start at 0, put this in your emacs init file:
(require 'linum) (setq linum-format (lambda (line) (propertize (number-to-string (1- line)) 'face 'linum)))
Setting line number to start at 0 is useful because some editors do that. See: bug#4274.
linum-mode is written by Markus Triska. Thanks Markus.