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

后端 未结 13 1017
执念已碎
执念已碎 2020-12-12 11:56

Notepad++ has a convenient feature: if you select a word in your text (not necessarily a keyword), the word is highlighted throughout the text. Can this be done in Emacs as

相关标签:
13条回答
  • 2020-12-12 12:19

    Commands in library highlight.el let you (un)highlight text matching a regexp (in this case a symbol), using overlays or text properties. You can cycle among the occurrences. Highlighting can be temporary or persistent. (more info).

    0 讨论(0)
  • 2020-12-12 12:22

    Try iedit. It highlights the word at point and lets you edit all occurrences of it easily. With an additional keystroke (C-'), it hides all the lines without that word in it. Very handy!

    0 讨论(0)
  • 2020-12-12 12:26

    What I use is idle-highlight

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

    M-x idle-highlight sets an idle timer that highlights all occurences in the buffer of the word under the point.

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

    ;; highlight words
    (add-hook 'prog-mode-hook (lambda () (idle-highlight-mode t)))
    
    0 讨论(0)
  • 2020-12-12 12:28

    Light-symbol will highlight whatever symbol point is over.

    Alternately, you can use occur, which lists all lines matching a regexp. It's useful to quickly see all functions in a class.

    0 讨论(0)
  • 2020-12-12 12:29

    Type C-s, then type the current word or type C-w. As a bonus, you can now hit C-s again to search for the word.

    This is called incremental search.

    0 讨论(0)
  • 2020-12-12 12:32

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

    alt text

    0 讨论(0)
提交回复
热议问题