Emacs中用于isearch-forward的键绑定

14

我在Windows 7上使用Emacs v24.3。我正试图学习如何重新映射按键绑定。

我在我的主目录中创建了一个名为“.emacs”的文件,其中包含一行:

 (global-set-key (kbd "C-f") 'isearch-forward)

我使用runemacs.exe启动Emacs。我找到一个不存在的文件,输入一些单词(在文本开头点击)并键入C-F查找。 I-search:提示显示,我可以逐步搜索文本。目前为止还好。

问题是,如果行为应该与默认的C-s搜索正向一样,那就不是这样。当我第二次键入C-f以搜索字符串的下一个出现时,唯一发生的事情是I-search提示出现在迷你缓冲区中。

我无法搜索字符串的下一个出现。此外,Del键应该在相反方向上重复搜索。当我使用C-s搜索时,它确实会发生,但当我使用C-f搜索时却没有发生。

因此,这个单一键映射似乎破坏了两件事情。我是在错误映射吗?还是这些都是错误?如果我映射错了,如何将C-f映射到isearch-forward命令?


可能是如何在Emacs中将“搜索”和“搜索重复”绑定到C-f?的重复问题。 - Mirzhan Irkegulov
2个回答

17

在您的一行文字中,添加以下内容:

(define-key isearch-mode-map "\C-f" 'isearch-repeat-forward)
问题在于isearch有自己的绑定,在启动增量搜索后会激活这些绑定。添加上述表达式会重新映射isearch-repeat-forward的绑定。
如果你对这些绑定感到好奇,你可以在进行增量搜索时输入C-h b以检查完整的键位图。

谢谢。关于 DEL 键 - Emacs 教程说 DEL 可以反向重复上一次搜索。我看到 isearch-mode-mapDEL 定义为用于删除字符的键。这种情况下,教程是错误的吗? - Karl

0
不,我不认为教程上说了那个。我想你指的是“搜索”部分和这段文字:
>> Type C-s again, to search for the next occurrence of "cursor".
>> Now type `<DEL>` four times and see how the cursor moves.

If you are in the middle of an incremental search and type <DEL>, the
search "retreats" to an earlier location.  If you type <DEL> just
after you had typed C-s to advance to the next occurrence of a search
string, the <DEL> moves the cursor back to an earlier occurrence.  If
there are no earlier occurrences, the `<DEL>` erases the last character
in the search string.  For instance, suppose you have typed "c", to
search for the first occurrence of "c".  Now if you type "u", the
cursor will move to the first occurrence of "cu".  Now type <DEL>.
This erases the "u" from the search string, and the cursor moves back
to the first occurrence of "c".

<DEL> 不会向后搜索。它会从搜索字符串中删除一个字符,并且仅对结果字符串的上一个匹配项进行搜索。 但是,在 C-s 后的第一个 <DEL> 不会改变搜索字符串。它只是移动到上一个匹配项。

教程文本并不错误,尽管可能有点难以阅读。如果您有改进建议或只是想让 Emacs Dev 知道您觉得它不清楚,请使用 M-x report-emacs-bug


感谢澄清。但是您所描述的不是我得到的行为。教程中说:>>如果您在键入C-s以前键入<DEL>,则<DEL>将光标移回早期出现的位置<<。在我的情况下,在Win 7上,它会删除文本中的一个字符。但无论如何,我可以看到意图是让C-r反向搜索,实际上也起作用。教程继续说,当没有先前出现的情况时,DEL将从搜索字符串中删除一个字符。但对我来说,字符被从文本中删除了。 - Karl

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接