"超级明星"或在emacs中找到等效光标下的单词

mmr*_*ins 30 vim emacs search editor

我是一个vim用户,最近一直在试用emacs以获得乐趣.我发现到目前为止我最缺少的功能是" 超级明星 "(通过键入*找到光标下的单词)功能,我还没有在emacs中找到相应的功能.如果它没有内置,我需要添加到我的emacs文件中以获得类似的东西?

Chr*_*sen 34

正如paldepind指出那样,isearch-forward-symbol-at-point(M-s.默认情况下)与*Vim 相当.此功能从GNU Emacs 24.4开始提供; 如果您的Emacs不同或更旧,请继续阅读替代方案.

通常我只是做(M-b...)C-s C-w... C-s.那是:

  1. M-b 移动到感兴趣的单词的开头
    • 零或更多这些
  2. C-s 开始I-Search
  3. C-w 从点开始抽出单词
    • 其中一个或多个
  4. C-s 找到下一场比赛
  5. 更多的C-s是找到以后的比赛
  6. RET 在最近的比赛中退出I-search
    • 或者一堆C-g中止回到原来的起始位置

以下是将其集成到I-Search中(通过C-s和调用C-r; C-h k C-s用于信息isearch).

(require "thingatpt")
(require "isearch")
(define-key isearch-mode-map (kbd "C-*")
  (lambda ()
    "Reset current isearch to a word-mode search of the word under point."
    (interactive)
    (setq isearch-word t
          isearch-string ""
          isearch-message "")
    (isearch-yank-string (word-at-point))))
Run Code Online (Sandbox Code Playgroud)

将其集成到I-Search中可以利用其单词匹配和区分大小写设置(C-s M-c C-*可以对单词下的单词进行区分大小写的搜索).

  • 如何使用`isearch-forward-symbol-at-point`,它默认绑定到`Cs .` (3认同)

out*_*tis 17

尝试 C-sC-w

  • 这是一个错误的答案.它假设该点位于单词的开头,而Vim中的*super star*功能可以在单词内的任何位置使用. (11认同)

hua*_*uan 10

这是一个开始:

(global-set-key (kbd "C-*")
  (lambda ()
    (interactive)
    (re-search-forward (format "\\b%s\\b" (thing-at-point 'word)))))


its*_*eyd 7

目前还有Smart Scan,一个提供此功能的轻量级附加软件包.

它可以从MELPA获得 ; 添加MELPA为启用列表的说明package-archives这里.

要安装它:

M-x package-install RET smartscan RET

然后,您可以通过它启用它

(global-smartscan-mode t) ;; Turn on Smart Scan globally
Run Code Online (Sandbox Code Playgroud)

向前和向后搜索的默认键绑定分别是M-nM-p.


PS:如果你有兴趣,介绍这个软件包的原始博客文章就在这里.