Emacs: Show Line Numbers

emacs has 2 line numbers mode:

  • Alt + x linum-mode -> old, hack, slow. Emacs 23.
  • Alt + x global-display-line-numbers-mode -> Emacs 26.


Emacs 26 has a new line number mode.

  • global-display-line-numbers-mode -> show line numbers in all buffers.
  • display-line-numbers-mode -> show line numbers in current buffers.

Put this in your emacs init file:

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

display-line-numbers-mode is written by Eli Zaretskii.


Emacs 23 has a line number mode. It shows line numbers in margin.

  • linum-mode -> toggle line number in current.
  • global-linum-mode -> toggle line number in all buffers.

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

(global-linum-mode 1)

As linum-mode is slow, you can use nlinum instead of linum-mode.

(if (version< emacs-version "26")
    (use-package nlinum
      :ensure t
      (global-nlinum-mode 1))