I mostly use isearch-forward
, 【Ctrl+s】, and isearch-backward
, 【Ctrl+r】, to search for words or phrases in a buffer. Sometimes, though, it’s convenient to see all the matches at once. Emacs has a set of commands that make this easy.
The easiest to use is highlight-phrase
, which is bound to the 【Meta+s h p】 sequence. It will ask you for a phrase and highlighting color and then highlight all the matching phrases in the buffer. The nice thing about highlight-phrase
is that any whitespace is automatically converted to arbitrary whitespace and initial lower-case letters are made case insensitive so it’s pretty much a “do what I mean” command.
The next command, highlight-regexp
, is a little more general. It’s bound to 【Meta+s h r】 and lets you highlight anything that matches an arbitrary regexp.
The command highlight-lines-matching-regexp
is similar to highlight-regexp
except that it highlights the entire line that contains the match to the regular expression. It is bound to 【Meta+s h l】.
Finally, you can un-highlight the matches with unhighlight-regexp
, bound to 【Meta+s h u】.
Summary
Key Sequence | Command |
---|---|
【Meta+s h p】 | highlight-phrase |
【Meta+s h r】 | highlight-regexp |
【Meta+s h l】 | highlight-lines-matching-regexp |
【Meta+s h u】 | unhighlight-regexp |
Update: let → set.