2

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?

Thanks.

nanny
  • 5,756
  • 1
  • 20
  • 38
Tim
  • 5,007
  • 7
  • 32
  • 61
  • 2
    There are lots of ways of doing it, search here: http://www.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. – Kaushal Modi Mar 25 '15 at 10:30

2 Answers2

5

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.

nanny
  • 5,756
  • 1
  • 20
  • 38
2

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

(setq lazy-highlight-cleanup nil)
hmehra
  • 23
  • 4
  • 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