Emacs: Show Line Numbers

By Xah Lee. Date: . Last updated: .


global-display-line-numbers-mode 2020-12-04
M-x global-display-line-numbers-mode
Alt+x global-display-line-numbers-mode
show line numbers in all buffers.
Alt+x display-line-numbers-mode
show line numbers in current buffer.

These are new in Emacs 26 (released in 2018-05).

Put this in your emacs init file:

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

They are written by Eli Zaretskii. Thank you Eli.


Emacs 23 (released in 2009) has a line number mode called linum-mode. It's a hack, and slows your emacs into a crawl if you have a thousand lines. [see Emacs 23.1 Features (released 2009-07)]

Alt+x linum-mode
toggle line number in current.
Alt+x global-linum-mode
toggle line number in all buffers.
linum-mode 2020-12-04 XGTdh
M-x linum-mode

To set it permanetnly, put this in your emacs init:

(global-linum-mode 1)

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

Put $5 at https://www.patreon.com/xahlee , or goto paypal.com and pay to Xah@XahLee.org . Message me on XahLee discord, say so, ask me questions.
Or Buy Xah Emacs Tutorial

Emacs Tutorial

Emacs Init

Emacs Keys


ELisp Examples

ELisp Write Major Mode

Emacs Init

Init Basics


text editing