如何在Emacs中将“search”和“search-repeat”绑定到C-f键?

20

如何在Emacs中将增量搜索(C-s)重新映射为C-f?

我尝试使用(global-set-key (kbd "C-f") 'isearch-forward),但第二个C-f不重复搜索,我需要使用C-s

然后我尝试了(global-set-key (kbd "C-f") 'isearch-repeat-forward),但第一个C-f没有开始搜索。

甚至我尝试了(global-set-key (kbd "C-f C-f") 'isearch-repeat-forward),但这会导致错误。

我想要使用C-f进行搜索和重复搜索命令,我该怎么做?

谢谢。

2个回答

18

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


3
完成了! (global-set-key (kbd "C-f") 'isearch-forward) (define-key isearch-mode-map "\C-f" 'isearch-repeat-forward) 非常感谢。 - Fernando Almeida

6

isearch-repeat-forwardisearch-mode-map 中定义。

要解决你的问题,请按照以下步骤操作:

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

(add-hook 'isearch-mode-hook
 (lambda ()
 (define-key isearch-mode-map (kbd "C-f") 'isearch-repeat-forward)
 )
)

编辑:实际上,您不需要添加钩子。Ross Patterson提供的答案是正确的。


使用了这个解决方案。谢谢。 - Fernando Almeida
为什么要在模式钩子中这样做,而不是像@ross-patterson在他的答案中那样只更改一次模式映射,使用单个define-key - Davor Cubranic

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