33

Emacs' hl-line-mode is just what i need but i would like to change it's horrible yellow color, anyone know how can i do that?

General Grievance
  • 4,555
  • 31
  • 31
  • 45
fakedrake
  • 6,528
  • 8
  • 41
  • 64

3 Answers3

60

I use (set-face-background hl-line-face "gray13").

here's what it looks like with a black background.

alt text

Very subtle. Mostly I notice it when moving the cursor, which is what I wanted.

If you want to see a display of all the various colors, try (list-colors-display). It will show a list of colors in a new buffer.

EDIT: heh heh, since I am getting upvoted for pretty pictures, here it is "live":

alt text

(ps: that animated gif was produced with the Cropper tool and the AnimatedGif plugin.)

Cheeso
  • 189,189
  • 101
  • 473
  • 713
  • 1
    Do not be seduced by the pretty pictures! Revel in the text-only goodness, just over there (*points*) (although the `hl-line-face` variable does looks like appropriate indirection for `'hl-line`) – phils Dec 23 '10 at 20:26
  • @phils - I think I read somewhere that `hl-line-face` was the preferred way to get to the face. I think. – Cheeso Dec 24 '10 at 00:14
  • Yeah, I would say the fact that it exists is probably sufficient evidence of that :) It seems highly unlikely that it would ever make a difference, mind, but I've changed my own config accordingly. – phils Dec 24 '10 at 08:52
  • 5
    You probably made it an after advice because having the `(set-face-background 'hl-line "gray13")` on top level results in an `Invalid face` error, but when you have it after the hl-line-mode has been loaded, then it works just fine. – hvrauhal Nov 05 '13 at 11:37
  • Thanks for `M-x list-colors-display` :D – Noah Sussman Feb 05 '19 at 18:03
13

M-x customize-group RET hl-line RET

and modify "Hl Line face".

Alternatively, you could use (for example):

(set-face-background 'hl-line "#333333")

edit: cheeso's answer would be the more robust approach for that second version.

phils
  • 71,335
  • 11
  • 153
  • 198
2

On top of all the nice answers, you can also do it with use-package as follows:

(use-package hl-line                                                                                                                                                                                                                                                                                                  
  :custom-face                                                                                                                                                   
  (hl-line ((t (:background "#aaaaaa")))))

hl-line is the customizible face added in Emacs 22 according to the author of hl-line+.

Dean Seo
  • 5,486
  • 3
  • 30
  • 49