Emacs: Show Line Numbers

By Xah Lee. Date: . Last updated: .

emacs has 2 line numbers mode.

emacs display line numbers mode 23786
emacs. Alt+x global-display-line-numbers-mode


Emacs 26 (released in 2018-05) has a new line number mode.

Put this in your emacs init file:

(when (version<= "26.0.50" emacs-version )

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 set it permanetnly, put this in your emacs init:

(global-linum-mode 1) ; always show line numbers

How to set linum 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.

Jump to a Line Number

Alt+x goto-line → move cursor to a given line position.

Emacs Show Line/Column Number

  1. Show Line Numbers
  2. Show Cursor Position
  3. Save Cursor Position

If you have a question, put $5 at patreon and message me.
Or Buy Xah Emacs Tutorial
Or buy a nice keyboard: Best Keyboards for Emacs


Emacs Lisp