1

I am asking this after having read this post:

How do I display line numbers in emacs (not in the mode line)?

I have tried using: M-x linum-mode and display-line-numbers-mode

After closing emacs and reopening, they are gone. Is there not a way to have emacs permanently display the line numbers?

5

In order for your changes to persist, you need to add them to your init file. If you've used any customize functionality, it probably generated one for you, and it's saved in ~/.emacs. If that isn't the case, you're better off putting it in ~/.emacs.d/init.el.

In order to have line numbers in all buffers and have them persistently, you can put

(global-display-line-numbers-mode)

into your init file.

If you're using an older version of Emacs, you'll want to use linum-mode, in that case you should put this in your init file isntead:

(global-linum-mode)
  • Both of those files are empty for me. And adding that line did nothing in both cases. – user1394 Oct 26 '18 at 21:12
  • You either have to evaluate contents of your new init file to see the changes right away, or restart Emacs. Also, if you have both files, ~/.emacs will take precedence if I recall correctly, so make sure you have only one of these files. – DoMiNeLa10 Oct 26 '18 at 21:37
  • Thank you for your continued help. I restarted everything. I am putting that line in an empty ~/.emacs file. And getting this error: Symbol's function definition is void: global-display-line-numbers-mode – user1394 Oct 26 '18 at 21:42
  • 1
    (global-linum-mode) for older versions of Emacs. – phils Oct 27 '18 at 9:12
0
  1. Menu Options > Show/Hide > Line Numbers for All Lines > Global Line Numbers Mode

  2. Menu Options > Save Options

Menus are your friends. They can be a good way to discover Emacs features.

You can also alternatively use Customize to set the equivalent option directly: M-x customize-option global-display-line-numbers-mode.

  • I only have a 'Line Numbers' completion (I do not see a 'Line Numbers for All Lines') under 'Show/Hide' and choosing that one simply toggles line number mode. – user1394 Oct 26 '18 at 21:52
  • I see. Your question doesn't specify any Emacs release. I guess you need release 26 or later to have those menu entries and option global-display-line-numbers-mode. I'll leave the answer, as it might help someone else. – Drew Oct 26 '18 at 23:10
  • Ah I see. Makes sense. Thank you and will just assume this is not possible in my release (I'm working on a specific server which I cannot modify). – user1394 Oct 26 '18 at 23:31

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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