How can I emulate Vim's * search in GNU Emacs?

前端 未结 9 1648
星月不相逢
星月不相逢 2020-12-23 16:57

In Vim the * key in normal mode searches for the word under the cursor. In GNU Emacs the closest native equivalent would be:

C-s C-w

But th

9条回答
  •  无人及你
    2020-12-23 17:26

    The highlight symbol emacs extension provides this functionality. In particular, the recommend .emacsrc setup:

    (require 'highlight-symbol)
    
    (global-set-key [(control f3)] 'highlight-symbol-at-point)
    (global-set-key [f3] 'highlight-symbol-next)
    (global-set-key [(shift f3)] 'highlight-symbol-prev)
    

    Allows jumping to the next symbol at the current point (F3), jumping to the previous symbol (Shift+F3) or highlighting symbols matching the one under the cursor (Ctrl+F3). The commands continue to do the right thing if your cursor is mid-word.

    Unlike vim's super star, highlighting symbols and jumping between symbols are bound to two different commands. I personally don't mind the separation, but you could bind the two commands under the same keystroke if you wanted to precisely match vim's behaviour.

提交回复
热议问题