125

I know how to display line numbers (and columns) in the mode-line, but I'd like emacs to display the line numbers for all the lines on the left-hand side. I've seen this done in vim and other text editors. How do I do this for emacs?

Luke Girvin
  • 200
  • 4
  • 15
Son of the Wai-Pan
  • 2,359
  • 4
  • 21
  • 30

3 Answers3

156

M-x linum-mode (or global-linum-mode), and put (global-linum-mode t) in your ~/.emacs (or ~/.emacs.d/init.el) to enable it at startup.

monotux
  • 1,787
  • 1
  • 10
  • 9
11
  • linum-mode → old, hack, slow. Emacs 23 (released in 2009).
  • global-display-line-numbers-mode → Emacs 26 (beta as of 2018-03-30)

Put this in your emacs init file:

(when (version<= "26.0.50" emacs-version )
  (global-display-line-numbers-mode))

http://ergoemacs.org/emacs/emacs_line_number_mode.html

rofrol
  • 1,849
  • 19
  • 17
11

This page:

lists a few different options.

monotux's answer is currently the first option listed there. An alternative (also listed) is NLinum:

You should be able to install from ELPA:

M-x package-install RET nlinum RET

and then use it e.g. like this:

(use-package nlinum
  :config
  (global-nlinum-mode))
icyrock.com
  • 5,247
  • 2
  • 31
  • 30
  • 10
    Just a link is not ideal for the SX format. – Prof. Falken Nov 15 '12 at 10:03
  • @Prof.Falken Especially when the link leads to a 404 Not Found. Please fix your answer. – byxor Jun 13 '17 at 12:58
  • 1
    Thanks both - agreed, though [monotux's answer](https://superuser.com/a/212669/48734) already has all the needed information. I edited to correct the link and provide an alternative one. – icyrock.com Jun 14 '17 at 03:37