I use C-s to search a pattern in a buffer. Then when I move the cursor, the highlighted matches lose highlight. Can I keep highlights however I move my cursor, or even edit the buffer?

What about when I search using regex?


  • 2
    There are lots of ways of doing it, search here: emacswiki.org/emacs/HighlightTemporarily for something that appeals to you.
    – wvxvw
    Mar 24 '15 at 18:07
  • 3
    See the isearch variable lazy-highlight-cleanup: Controls whether to remove extra highlighting after a search. If this is nil, extra highlighting can be "manually" removed with lazy-highlight-cleanup.
    – lawlist
    Mar 24 '15 at 18:29
  • Related. There's also an hl-anything package available on MELPA. Mar 25 '15 at 10:30

There's some built-in highlighting functionality bound to key sequences starting with M-s h. To see them all, type M-s h C-h to read about the Global Bindings Starting With M-s h.

The specific functionality you want is bound to M-s h r, highlight-regexp.


You can do this by using lazy highlight in your .emacs

(setq lazy-highlight-cleanup nil)
  • Yes, but this is a user option, so you might consider using M-x customize-option. Also, lazy-highlight-cleanup is a command, which you can use to remove the highlighting on demand at any time.
    – Drew
    Jun 13 '16 at 22:38

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.