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?

3 Answers 3

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.

6
  • Is there a way to do this with column numbers?
    – Topo
    Nov 24, 2012 at 20:09
  • For any late readers: M-x column-number-mode is one way to display the current column your pointer is at.
    – monotux
    Mar 13, 2014 at 11:42
  • There is neither an init.el file in my .emacs.d directory nor a .emacs file in my ~. Where can I find them? Jul 4, 2016 at 18:48
  • 2
    You can create one if you don't already have a config. Sep 10, 2016 at 18:56
  • This worked for me. Heads up for Windows users - this file is located in C:\Users\username\AppData\Roaming directory, and is called ".emacs". Just add (global-linum-mode t) at the end of the file. Oct 1, 2017 at 16:25
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))
3
  • 10
    Just a link is not ideal for the SX format. Nov 15, 2012 at 10:03
  • @Prof.Falken Especially when the link leads to a 404 Not Found. Please fix your answer.
    – byxor
    Jun 13, 2017 at 12:58
  • 1
    Thanks both - agreed, though monotux's answer already has all the needed information. I edited to correct the link and provide an alternative one. Jun 14, 2017 at 3:37
8
  • 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

2
  • This worked for me Aug 20, 2018 at 18:22
  • Adding (global-display-line-numbers-mode) to .emacs file works in Emacs 26!
    – joseluisq
    Apr 1, 2019 at 21:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.