Changing highlight line color in emacs
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).
Farzam
Updated on June 02, 2022Comments
-
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.
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.
-
Farzam almost 11 yearsThanks, 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 almost 11 yearsI guess you are using
show-paren-mode
and you haveshow-paren-style
set asexpression
. Use M-x customize-variable with show-paren-style and set it toparenthesis
(or disable the mode if you don't like it). But I might be wrong, and there might be another mode at play... -
Farzam almost 11 yearsthat 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 almost 11 years
M-x describe-face
will help see which face is used to highlight a particular character. -
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 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 over 10 yearsThat'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 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 over 10 yearsYep. 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 about 7 yearsI think the keep-syntax-hilighting command should be
(set-face-foreground 'hl-line nil)
. Is that a typo?