reddit / emacs

How tf do you enable line numbering?

CherrrySzczery · 2022-01-25 17:53
What I tried: ``` (setq line-number-mode t) (setq global-linum-mode t) (global-linum-mode t) ``` clicking in menu enable line numbers and save options. I have emacs 27.2
pathemata · 2022-01-25 18:15
`M-x` (alt key with x) then `global-linum-mode`. Or `(global-linum-mode)` go to the end of the expression and type `C-x e` to call `eval-last-sexp`.
crawsphi · 2022-01-25 18:18
As of Emacs 26 the best way is the `display-line-numbers-mode`, which can be activated for all buffers with the `global-display-line-numbers-mode` command.
xwfwuerbt0o3z · 2022-01-25 18:20
Your second option in \`.emacs.d/init.el\` should work.
weevyl · 2022-01-25 18:21
I don't need everything to have line numbers, so I just added it as a hook for each mode where I wanted line numbering: (add-hook 'xxx-mode-hook 'linum-mode) where xxx-mode should be replaced with the actual mode name. Added that to my init.el file and all was good.
JDRiverRun · 2022-01-25 18:59
If you don't want line numbers on all the time, for space-saving considerations, `consult-goto-line` is wonderful. It temporarily shows line numbers and gives a *preview* of the line you are selecting.
T_Verron · 2022-01-26 10:30
If you have emacs 26 or more recent, display-line-numbers-mode has much better performance than linum-mode.
centzon400 · 2022-01-26 13:20
I snagged this from Prot's config: (use-package emacs :config (defun prot/toggle-line-numbers () "Toggles the display of line numbers. Applies to all buffers." (interactive) (if (bound-and-true-p display-line-numbers-mode) (display-line-numbers-mode -1) (display-line-numbers-mode))) :bind (("<f7>" . prot/toggle-line-numbers))) Thanks, Prot!
weevyl · 2022-01-26 17:02
Thanks for the tip! I will give it a try.
oantolin · 2022-01-27 01:48
Here's how you can answer these questions directly in Emacs: run `M-x apropos RET line numbers RET`, the listing includes `display-line-numbers` which sounds promising. Pressing `RET` on `display-line-numbers` or clicking it with the mouse pops up a help buffer describing it. The help buffer says "You can customize this variable" and "customize" is a link; clicking the link or pressing `RET` on it lets you configure the line number display.
junglee33 · 2022-01-27 04:31
yup ! fwiw, my mode line displays both line and column numbers (nicely tucked away without cluttering the buffer with useless information) when screen real-estate is an issue f.e. on a latop etc. i definitely don't want that to be there...