【问题标题】:Emacs key binding for isearch-forward用于 isearch-forward 的 Emacs 键绑定
【发布时间】:2013-08-10 00:52:03
【问题描述】:

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

我在我的主目录中创建了一个 .emacs 文件,它包含一行:

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

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

问题是,如果假设行为与默认的isearch-forward 击键C-s 相同,则不是。当我再次键入C-f 以搜索字符串的下一个出现时,唯一发生的事情是I-search 提示出现在迷你缓冲区中。

我无法搜索下一次出现的字符串。此外,假设Del 键会反向重复搜索。当我使用C-f 搜索时,我不会发生这种情况(尽管当我使用C-s 搜索时会发生这种情况)。

所以这个单键映射似乎打破了两件事。我映射错了吗?还是这些错误?如果我映射错误,如何将C-f 映射到isearch-forward 命令?

【问题讨论】:

标签: emacs


【解决方案1】:

除了你的一行,添加:

(define-key isearch-mode-map "\C-f" 'isearch-repeat-forward)

问题在于 isearch 有自己的绑定,一旦您开始增量搜索,这些绑定就会处于活动状态。添加上面的表达式会重新映射isearch-repeat-forward 的绑定。

如果您对这些绑定感到好奇,可以在执行增量搜索时输入 C-h b 以检查完整的键盘映射。

【讨论】:

  • 谢谢。关于 DEL 键 - Emacs 教程说 DEL 反向重复最后一次搜索。我看到isearch-mode-mapDEL 定义为用于删除字符的键。猜猜在这种情况下教程是错误的?
【解决方案2】:

不,我不认为教程这么说。我认为您指的是 SEARCHING 部分和这段文字:

>> 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".

&lt;DEL&gt; 不会向后搜索。它从搜索中删除一个字符 字符串,然后搜索移动到(仅)结果字符串的上一个匹配项。 但是C-s 之后的第一个&lt;DEL&gt; 不会改变搜索字符串。这只是 移动到上一个匹配项(仅)。

教程文字没有错,虽然可能有点难 读。如果您有改进建议或只是想让 Emacs 开发人员知道您觉得不清楚,请使用M-x report-emacs-bug

【讨论】:

  • 感谢您的澄清。但你描述的不是我得到的行为。教程说>>如果您在键入 C-s 后键入 以前进到搜索字符串的下一个匹配项,则 会将光标移回到较早出现的位置C-r 的意图是反向进行搜索,事实上,这是可行的。教程接着说DEL 将在没有先前出现的情况下删除搜索字符串中的一个字符。但同样,对我来说,该字符已从文本中删除。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-15
  • 1970-01-01
相关资源
最近更新 更多