25

How can I add line numbers to Emacs?

Please explain, I'm an absolute beginner.

AKGMA
  • 385

2 Answers2

27

If you're running it in default mode, it's in the menu: Options > Show/Hide > Line Numbers. Then Options > Save Options to save it for future sessions.

If you're running it in a terminal (emacs -nw), then it's M-x line-number-mode. M- is usually the Windows key, but may be Alt, or you can press Esc followed by x.

(Edit: The above only affects the mode line. For line numbers in the margin, you want M-x linum-mode, or more likely (setq global-linum-mode t) in your ~/.emacs.)

geekosaur
  • 11,597
21

Add (global-linum-mode t) to ~/.emacs.d/init.el

  • 1
    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. – Kirill Yunussov Oct 01 '17 at 16:24
  • Could also be in the "C:\Users\username" directory – Kirill Yunussov Oct 02 '17 at 12:49
  • how do you add a space between the line number and the text? because adding just (global-linum-mode t) shows the line numbers and the text without spaces. – m4l490n Jan 18 '18 at 08:02