如何实现直接定位跳转到同行内容的同一单词的第n个occurrence

目前使用Helm swoop进行搜索时,同一行内即使有同一单词的多次出现,但匹配结果在Helm mini buffer中总是作为同一个swoop匹配结果条目出现的。导致在helm mini buffer中按下回车后,只能默认跳转到改行内的该单词的第一次occurrence上。

但是有时候,我可能需要直接跳转到第2个,第n个occurrence上,对这第n个出现,进行修改。

不知道在Spacemacs中,想要实现这个操作,需要安装什么package,或者需要对Helm swoop进行如何配置?

谢谢!

我是helm-swoop的maintainer,建议你去github写一个issue,我这两天研究下怎么实现

1 个赞

可试试 Swiper 结合上 Avy,貌似有现成的解决方案。

(defun helm-swoop-goto-line-action-hack ($line)
  (run-hooks 'helm-swoop-before-goto-line-action-hook)
  (helm-swoop--goto-line
   (when (string-match "^[0-9]+" $line)
     (string-to-number (match-string 0 $line))))
  (let (($regex
          (mapconcat 'identity
                     (split-string helm-pattern " ")
                     "\\|")))
    (when (or (and (featurep 'migemo) helm-migemo-mode (migemo-forward $regex nil t))
              (let ((rep (if helm-current-prefix-arg
                             (prefix-numeric-value helm-current-prefix-arg)
                           1))
                    (end (point-at-eol)))
                (dotimes (_ rep) (re-search-forward $regex end t))
                t))
      (funcall helm-swoop-flash-region-function
               (match-beginning 0) (match-end 0))
      (goto-char (match-beginning 0))
      (run-hooks 'helm-swoop-after-goto-line-action-hook)))
  (helm-swoop--recenter))

(advice-add #'helm-swoop--goto-line-action :override #'helm-swoop-goto-line-action-hack)

暂时试一下这个hack,用C-u n RET 跳转到第N个occurence

1 个赞

感谢您的神速回复!!

我明天尝试一下。

swiper有个swiper-isearch,同样是这个minibuffer/popup界面,但是同一行上多个occurrence会在popup里显示为多个行

wow, 这个好像就是我想要的!

Thanks!

我是想让cireu给helm实现这个功能来着。。当然你要是对helm ivy没偏好也可以直接叛变。。

helm-swoop的结构太混乱了(作者似乎是写Perl的,变量一堆dollar sign),一时间不太想动。。

之前好像有看到过道友讨论swiper和helm的区别。(似乎swiper在搜索上更强大,helm与Spacemacs 配合整合更全面、更成熟)

我目前一直主力用的是helm,而且为helm swoop定义了快捷键。感觉helm用着已经很顺手。进来并没有再尝试swiper过。

也是希望helm能把这个类似swiper-isearch的功能,给实现到helm swoop里!那就太好了!

我这里swiper-isearch并没有你们说的效果啊

看prompt你这个还是swiper,试试swiper-isearch

doom的作者说过swiper-helm比helm-swoop所有方面都强

你得把配置告诉大神吧

sorry,自己配置确实错了,低级错误,帖子删除了,不打搅大神了。。。