How do I highlight a region and it make it remain highlighted when point moves on.
Why would I want that? So I can make important snippets of code stand out when I review it later.
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.
Sign up to join this communityHow do I highlight a region and it make it remain highlighted when point moves on.
Why would I want that? So I can make important snippets of code stand out when I review it later.
Library Highlight (highlight.el
) lets you highlight any number of regions in various ways, including using regexps, using any number of faces.
One easy way to highlight an expanse of text (and have it persist until you remove it) is to sweep your mouse over it - like using a highlighter pen. This is command hlt-highlighter
. By default, the command is bound to C-x down-mouse-2
, which means that you use it by hitting C-x X
and then pressing and dragging mouse-2
(the second or middle mouse button) across the text. With a prefix argument (i.e., C-u C-x X
+ drag mouse-2
) you are prompted for the face to use.
(By default, C-x X
is the prefix key that keymap hlt-map
is bound to. Lots of highlighting and highlight-erasing keys are bound in that map. You can put the keymap on any other prefix key or bind individual highlighting and erasing commands to more convenient keys. I put hlt-highlighter
on C-x down-mouse-2
, for example.)
A quick and easy way to highlight a single region of text, and have that highlighting persist until you put it on a different region, is to use the secondary selection.
For that, just press and hold the Meta key (typically Alt
) while you drag mouse-1
.
If you use library second-sel.el
then you can access any number of such secondary selections on a ring, among other features.
Are you looking for hi-lock-mode
? You can highlight matching regexps or highlight regions by using highlight-phrase: C-x w p phrase RET face RET
.
https://www.gnu.org/software/emacs/manual/html_node/emacs/Highlight-Interactively.html
M-s h
prefix, so you can use M-s h C-h
to see a list of related commands. Also worth noting you can save the current set of highlighted patterns to the current file, so that you can restore them later.
– glucas
Feb 7 '17 at 21:14
M-s
on my emacs (25.3.1 on a Mac) starts a regular expression isearch. I thought that was a standard binding. And I mission something?
– Troy Daniels
Jan 14 '19 at 22:58
bm-toggle
to create a bookmark at the point. – ebpa Feb 7 '17 at 20:11