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?
For Emacs version >= 26 you should use
As @eric-brown mentioned you can use
Another good idea is to use
(add-hook 'prog-mode-hook 'linum-mode) in your init.el to automatically enable linum-mode in all programming modes.
If you are using Emacs 26 or newer, you can use
** Emacs now supports optional display of line numbers in the buffer. This is similar to what 'linum-mode' provides, but much faster and doesn't usurp the display margin for the line numbers. Customize the buffer-local variable 'display-line-numbers' to activate this optional display. Alternatively, you can use the 'display-line-numbers-mode' minor mode or the global 'global-display-line-numbers-mode'. When using these modes, customize 'display-line-numbers-type' with the same value as you would use with 'display-line-numbers'.
nlinum-mode is another option. It has the same interface as
linum-mode, so you can use the same hooks, but it uses a different technology to be more performant. Quote from
;; This is like linum-mode, but uses jit-lock to be (hopefully) more efficient.
You can install it via GNU Elpa via the usual
linum-mode is a good choice.
If you don't always want to see line numbers, like me, you can use this trick from the excellent What the .emacs.d!? blog.
This temporarily enables
linum-mode when you run
Here's the code from his blog:
(global-set-key [remap goto-line] 'goto-line-with-feedback) (defun goto-line-with-feedback () "Show line numbers temporarily, while prompting for the line number input" (interactive) (unwind-protect (progn (linum-mode 1) (goto-line (read-number "Goto line: "))) (linum-mode -1)))