Emacs: Display Line Numbers linum-mode

By Xah Lee. Date: . Last updated: .

Emacs 23 (released in ) has a line number mode. It shows line numbers in margin. 〔➤see Emacs 23.1 New Features (released 2009-07)

emacs line numbers
Emacs with linum-mode on.

To toggle it in current buffer, call linum-mode.

To toggle globally, call global-linum-mode.

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.

Like it? Buy Xah Emacs Tutorial. Thanks.

or, buy something from Best Keyboard for Emacs