自动包装 I-search? [英] Automatically wrapping I-search?

查看:13
本文介绍了自动包装 I-search?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Vim 中,我可以 :set wrapscan 以便当我进行增量搜索时,无论第一个匹配项是在光标上方还是下方,光标都会跳转到第一个匹配项.

In Vim I can :set wrapscan so that when I do an incremental search, the cursor jumps to the first match whether the first match is above or below the cursor.

在 Emacs 中,如果我通过 C-s 开始搜索,如果第一个匹配项位于光标上方,则搜索失败并显示 Failing I-search.如果我再次点击 C-s,它就会包装搜索,说 Wrapped I-search.在 Vim 中,如何默认换行和跳转光标,而不必第二次 C-s?

In Emacs, if I start a search via C-s, the search fails saying Failing I-search if the first match is above the cursor. If I hit C-s again it then wraps the search, saying Wrapped I-search. How do I wrap and jump the cursor by default as in Vim, without having to C-s a second time?

推荐答案

最简单的方法是使用以下 deadvice:

The easiest way to do this is to use the following defadvice:

(defadvice isearch-repeat (after isearch-no-fail activate)
  (unless isearch-success
    (ad-disable-advice 'isearch-repeat 'after 'isearch-no-fail)
    (ad-activate 'isearch-repeat)
    (isearch-repeat (if isearch-forward 'forward))
    (ad-enable-advice 'isearch-repeat 'after 'isearch-no-fail)
    (ad-activate 'isearch-repeat)))

当 Isearch 失败时,它会立即通过换行再次尝试.请注意,当没有匹配项时,暂时禁用此 deadvice 以防止无限循环非常重要.

When Isearch fails, it immediately tries again with wrapping. Note that it is important to temporarily disable this defadvice to prevent an infinite loop when there are no matches.

这篇关于自动包装 I-search?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆