6

Running M-x hl-line-mode enables highlighting for the current buffer.

How can i set highlighting current line to be enabled in init.el?

Dan
  • 32,584
  • 6
  • 98
  • 168

2 Answers2

15

just add this to your .emacs or init.el file : (global-hl-line-mode 1).

Chakravarthy Raghunandan
  • 3,132
  • 2
  • 18
  • 42
  • so easy was that! :-) –  Jul 31 '16 at 19:02
  • If you want to customize any part of emacs, press `M-x RET customize-group RET emacs RET`. A buffer will open listing all the groups you can customize in emacs(like editing, programming, environment, etc.). There will also be a search field in the top of the buffer. You could also enabled hl-line globally by going to customize-group, and setting the global-hl-line-mode to a non-nil value. – Chakravarthy Raghunandan Jul 31 '16 at 19:16
9

@Chakravarthy Raghunandan answered your question completely and succinctly.

But you owe it to yourself to learn to ask Emacs -- that will help you much more, both immediately and in the long run. One of the goals of this particular Stack-Exchange site is to help not only by answering specific questions, but by helping you learn to help yourself.

This kind of question is answered immediately by asking the Emacs manual (C-h r) what it has about hl-line-mode: just type i hl-line-mode (i is bound to the command Info-index). That takes you immediately to node Cursor Display of the manual, where you see this:

To make the cursor even more visible, you can use HL Line mode, a minor mode that highlights the line containing point. Use M-x hl-line-mode to enable or disable it in the current buffer. M-x global-hl-line-mode enables or disables the same mode globally.

It really couldn't be simpler, in this case. No need to open a web browser, go to a Q&A site, and type up your question. Just ask Emacs.

You have the hypertext manual(s) ready-to-hand at all times when you are in Emacs. C-h i opens the manuals browser (Info) for any installed manual, including the Emacs manual and the Elisp (Emacs-Lisp) manual. If you haven't yet taken time to get to know Info, I recommend you start by looking at the Info manual about Info: C-h i m Info.

Drew
  • 75,699
  • 9
  • 109
  • 225
  • 1
    What do I have to do when `C-h r i` gives me _The Info diretory node has no index__? – buhtz Feb 07 '21 at 21:20
  • 1
    Which manual has no index? I'd suggest filing a bug to the maintainers of the relevant library, if not part of regular Emacs, or `M-x report-emacs-bug` if it is part of regular Emacs. `i` is generally recommended as the best (or one of the best) ways to find stuff in Emacs. If some manual has no index then I'd consider that a bug, or at least a place where there's room for improvement. – Drew Feb 07 '21 at 23:58
  • But you said `C-h r`, which is the Emacs manual. It definitely **does** have an index. Perhaps you are doing something wrong. Do you see the same problem (no index) if you start Emacs using `emacs -Q` (no init file)? If not then bisect your init file to find the culprit. – Drew Feb 08 '21 at 00:00
  • And I see now the error message you quote says that you are not in *any* manual - you are at the directory node, which is above all manuals. So see previous comment - clearly `C-h r` didn't take you to the Emacs manual, or you didn't actually use `C-h r`. – Drew Feb 08 '21 at 00:01
  • 1
    See @Drew It is not so easy as you stated. Of course I hit `C-h r`. – buhtz Feb 08 '21 at 11:18
  • 1
    If `C-h r` doesn't take you to the Emacs manual then the problem is likely in your init file. Do you see the same problem when you start using `emacs -Q`? – Drew Feb 08 '21 at 16:03
  • 1
    Someone want to explain the downvote? – Drew Feb 14 '23 at 17:00
  • Someone want to explain another downvote? – Drew Feb 15 '23 at 16:59