3

When I incrementally search for a phrase with C-S, emacs usually highlights all matching results visible in the buffer by giving them a different background color. However, my current theme apparently uses the same background color as the normal background color, meaning I can't see the difference.

How can I specify a background color for matching search results?

1 Answer 1

3

You are looking for the lazy-highlight face.

You didn't mention what color your background is, so modify the below as needed:

(set-face-attribute 'lazy-highlight nil :background "green")

Similarly, you can set the foreground color with:

(set-face-attribute 'lazy-highlight nil :foreground "black")

And you can combine the two with:

(set-face-attribute 'lazy-highlight nil :foreground "black" :background "green")

To figure out what face needed to be modified, I did M-x describe-char as described in this answer. I first had to set lazy-highlight-cleanup to nil so that the selection wasn't cleared when exiting the isearch.

3
  • Perfect. I also ended up setting the foreground color with (set-face-attribute 'lazy-highlight nil :foreground "black")
    – Ben
    Aug 4, 2016 at 19:51
  • @Ben: You can also combine the two; see my updated answer. Aug 4, 2016 at 20:26
  • I have tried (set-face-attribute 'lazy-highlight nil :foreground "black" :background "green") which does not change the selected main word on the isearch
    – alper
    Jan 31, 2020 at 22:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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