How to select all occurrences of a word in an Emacs buffer?

Notepad ++ has a convenient function: if you select a word in your text (optionally a keyword), the word will be highlighted in the entire text. Can this be done in Emacs? And if so, how?

It does not have to work exactly the same way as Notepad ++ (i.e. via selection); Ideally, I would like to set up key binding, which causes the selection of all occurrences of the word under the cursor.

It would be great if the backlight was constant, i.e. moving a point from the selected word should not remove the selection.

In addition, it would be useful if there was a solution that allows you to move between the backlight (using custom key bindings).

+60
highlighting emacs
Dec 22 '08 at 6:20
source share
10 answers

Perhaps highlight-symbol.el at http://nschum.de/src/emacs/highlight-symbol/ is what you are looking for:

alt text

+33
Dec 23 '08 at 0:50
source share

hi-lock offers are good. I think it is easier to use Mx versions, though:

Mx highlight-regexp RET <REGEXP>

Mx highlight-phrase RET <REGEXP>

highlight-phrase is just a little sugar around highlight-regexp , which ignores case and translates the space into a regular expression to match arbitrary spaces. Handy

+65
Jan 09 '09 at 4:11
source share

Type Cs , then type the current word or type Cw . As a bonus, you can press Cs again to find the word.

This is called incremental search.

+31
Dec 22 '08 at 8:53
source share

What I use is inactive

http://www.emacswiki.org/emacs/IdleHighlight

Mx idle-highlight sets an idle timer that selects all occurrences in the word buffer below the dot.

To enable it for all programming modes, in ~/.emacs.d/init.el :

 ;; highlight words (add-hook 'prog-mode-hook (lambda () (idle-highlight-mode t))) 
+13
Apr 28 2018-11-11T00:
source share

Light-symbol will highlight any point on the symbol.

Alternatively, you can use occur , which lists all the strings matching the regular expression. This is useful for quickly viewing all the functions in a class.

+10
Dec 22 '08 at 6:39
source share

Try http://www.emacswiki.org/emacs/msearch.el All occurrences of the text selected with the cursor are highlighted. You need to drag the line you want to highlight. This makes it easy to change selections without changing the backlight.

If you want to keep the selection of the line, you can freeze it.

You can enslave a buffer for another buffer. Text selected in the main buffer will also be highlighted in the sub buffer. This is useful for comparing buffers. It is also useful for taking notes in one buffer when you examine text in another. You can have a set of keywords in the notes buffer. Drag on such a keyword and its occurrences in the studied text will be highlighted.

I have been using this material for many years. I recently added freeze. So maybe something is broken. If so, leave me a note at http://www.emacswiki.org/emacs/msearch or here.

+6
Aug 22 '13 at 16:09
source share

It may not be as good as you hoped, but if you put

 (global-hi-lock-mode 1) 

in your .emacs file, then you can type Cx wh REGEX <RET> <RET> to highlight all the REGEX and Cx wr REGEX <RET> events to highlight them again. Again, not as elegant as you would like, but it will work.

+5
Dec 22 '08 at 6:37
source share

Check Interactive Highlight

Must be:

C - x w h word <RET> <RET>

+3
Dec 22 '08 at 6:37
source share

Commands in the highlight.el (un) library, select the text that matches the regular expression (in this case, the character) using overlays or text properties. You can cycle through events. The allocation may be temporary or permanent. (more) .

+2
Sep 05 2018-11-11T00:
source share

Try iedit.el. It highlights the word at a point and makes it easy to edit all its occurrences. With an additional keystroke (C- '), it hides all lines without this word. Very comfortably!

+1
Oct 31 '11 at 3:45
source share



All Articles