Changing highlight line color in emacs

18,485

Solution 1

That would be an easy fix if you customize your init file (~/.emacs, ~/.emacs.el, or ~/.emacs.d/init.el)

Turn on hl-line:

(global-hl-line-mode 1)

Set any color as the background face of the current line:

(set-face-background 'hl-line "#3e4446")

To keep syntax highlighting in the current line:

(set-face-foreground 'highlight nil)

Solution 2

M-x customize-face RET hl-line will help you. Just pick a face you like (you can type the same command with the other theme installed, just to peek the values you like).

Share:
18,485
Farzam
Author by

Farzam

Updated on June 02, 2022

Comments

  • Farzam
    Farzam almost 2 years

    I installed emacs 24 and also installed prelude and I wanted to change the theme from zenburn to tango-dark. But the color that the line is highlighted is yellow and I don't like that. I want it to be like the gray color in zenburn. tango-dark theme with hl-line enabled(yellow)

    zenburn theme with hl-line enabled(dark gray)

    What should I do? I prefer not to turn off the hl-line but when I tried that I saw that the space between parentheses () are highlighted with the same yellow color. (In zenburn theme that didn't happen). I also know that this is not part of the tango theme because when I run vanilla emacs(sudo emacs) with tango theme no such highlighting happens. tango-dark theme with hl-mode disabled vanilla emacs with tango-dark theme

  • Farzam
    Farzam almost 11 years
    Thanks, that solved the first problem but I still have the problem in the third image(yellow highlighting between parentheses. How could I disable that?
  • juanleon
    juanleon almost 11 years
    I guess you are using show-paren-mode and you have show-paren-style set as expression. Use M-x customize-variable with show-paren-style and set it to parenthesis (or disable the mode if you don't like it). But I might be wrong, and there might be another mode at play...
  • Farzam
    Farzam almost 11 years
    that didn't help. I think that is disabled. there is also another problem in highlighting line. as you see in zenburn color theme, the syntax highlighting in the line is not changed but in the tango, all the characters are shown in white. How could I change it to look like zenburn.
  • Bozhidar Batsov
    Bozhidar Batsov almost 11 years
    M-x describe-face will help see which face is used to highlight a particular character.
  • Farzam
    Farzam almost 11 years
    @BozhidarBatsov: Thanks, that was smartparens.el (fixed). How could I make it keep the syntax highlighting?(See my previous comment)
  • juanleon
    juanleon almost 11 years
    @Farzan, what you need to do is customize-face hl-line and then set the background color of that face, but not the foreground color. In other words, the only "ticked" checkbox should be the background. That way the foreground colors will be "respected" (i.e., not set white).
  • dimitarvp
    dimitarvp over 10 years
    That's a no-go. I am also using tomorrow-theme (github.com/chriskempson/tomorrow-theme), so that might be influential. In any case, your described method doesn't work.
  • Admin
    Admin over 10 years
    @dimitko That should work in at least Emacs 24, only if you put them in the right place - these could have been overridden by your other configurations or installed packages.
  • dimitarvp
    dimitarvp over 10 years
    Yep. I wanted to point that out but wasn't clear enough. The way to solve it is, of course, to move your customizations after the loading / activating of your theme, which wasn't the case in my config .
  • mkvoya
    mkvoya about 7 years
    I think the keep-syntax-hilighting command should be (set-face-foreground 'hl-line nil). Is that a typo?