views:

2263

answers:

6

In Notepad++ editor, there's a convenient feature: if you select a word in your text (not necessarily a keyword), the word is highlighted throughout the text. Is there any similar way in Emacs? Not necessarily with selection, I think something like C-"something" M-"something else" which highlights all words same as the word under the cursor would be nicer even.

To summarize: light-mode and highlight-mode both can highlight the word under the cursor. However, when I scroll with the mouse, the text cursor also changes it's position and the highlight disappears, which sort of limits it's applicability.

In addition, highlight-mode let you make several permanent highlights with different colors, and they don't disappear if you move the cursor, and you can navigate between them using hotkeys. There's an issue with it, which might be a bug (I can't say for sure, with my knowledge of EL close to zero, however I managed to fix it nonetheless), when Emacs complains about a void variable and can't load the mode.

+3  A: 

This may not be as nice as what you were hoping but if you put

(global-hi-lock-mode 1)

in your .emacs file then you can type C-x w h REGEX <RET> <RET> to highlight all occurances of REGEX, and C-x w r REGEX <RET> to unhighlight them again. Again, not as elegant as you'd probably like, but it'll work.

dancavallaro
+2  A: 

Check Interactive Highlighting

Should be:

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

CMS
the link is 404 :(
Arthur Ulfeldt
+6  A: 

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.

ieure
+3  A: 

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 ;-)

ShreevatsaR
This is what I would suggest. Incremental search is the way to go.
Christian Davén
+5  A: 
polyglot
I tried it but couldn't get it working - emacs complained about "Symbol's value as variable is void: highlight-symbol-idle-delay".
Headcrab
I did have that particular problem. I ended up commenting out the entire (defcustom highlight-symbol-idle-delay...) part, and move (defvar highlight-symbol-idle-delay...) before (defun highlight-symbol-update-timer...), which will avoid the error.
polyglot
Yes, finally I did the same exact thing.
Headcrab
+5  A: 

The hi-lock suggestions are good. I think it's easer to use the M-x versions, though:

M-x highlight-regexp <REGEXP>

M-x highlight-phrase <REGEXP>

highlight-phrase is just a bit of sugar around highlight-regexp that ignores case and translates a space in the regex to match arbitrary whitespace. Handy.

jrockway