自动包装I搜索? [英] Automatically wrapping 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中,如果我通过 Cs
开始搜索,则搜索失败,表示失败I-search 如果第一个匹配在光标上方。如果我再次点击 C-s
,那么它将包装搜索,称为<包裹I搜索。默认情况下,如Vim中所包含和跳转光标,而不必再次使用 Cs
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?
推荐答案
最简单的方法是使用以下defadvice:
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失败时,它立即重新包装。请注意,暂时禁用此defadvice以防止无匹配时无限循环非常重要。
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搜索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!