How can I add line numbers to Emacs?
Please explain, I'm an absolute beginner.
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
.)
linum-mode
to the answer.
May 6, 2011 at 19:48
(setq global-linum-mode t)
is not working when I add this line to .emacs.d/init.el, I just change it to(global-linum-mode t)
and it works. Any reasons why?
Dec 28, 2015 at 2:15
Add (global-linum-mode t)
to ~/.emacs.d/init.el