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?

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.

  • Perfect. I also ended up setting the foreground color with (set-face-attribute 'lazy-highlight nil :foreground "black") – Ben Aug 4 '16 at 19:51
  • @Ben: You can also combine the two; see my updated answer. – Scott Weldon Aug 4 '16 at 20:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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