有没有办法在nrepl中进行历史搜索?

问题描述 投票:0回答:3

你知道当你在 bash 中点击向上箭头时,它会如何填充你输入的最后一个命令吗?在nrepl中有什么办法可以做到这一点吗?

到目前为止,我一直在进行反向搜索(C-r),输入相关行的前几个字符,杀死该行(C-k),跳转到缓冲区的末尾(M ->)并拉动被杀死的线(C-y)。有更简单的方法吗?

emacs clojure nrepl
3个回答
12
投票

您可以使用

M-p
M-n
在输入历史记录中上下导航。此外,当前输入可以用作搜索模式,即输入要匹配的命令的开头,然后
M-p
将带您到下一个匹配。这使用了函数
nrepl-previous-input
nrepl-next-input
。如果您不喜欢这些按键绑定,您还可以重新绑定到
<up>
<down>
:

(define-key nrepl-mode-map (kbd "<up>") 'nrepl-previous-input)
(define-key nrepl-mode-map (kbd "<down>") 'nrepl-next-input)

只需将其添加到您的

.emacs
(如果您不想重新启动 Emacs,请在每行之后评估
C-x C-e
)。另请注意,
M-n
M-p
可能会绑定到其他 REPL 和 comint 等模式中的类似功能。


4
投票

如果您使用Cider,您可以将以下内容添加到您的用户配置中:

(define-key cider-repl-mode-map (kbd "<up>") 'cider-repl-previous-input)
(define-key cider-repl-mode-map (kbd "<down>") 'cider-repl-next-input)

要在下次打开 repl 时保留历史记录,您还可以选择以下选项:

(setq cider-repl-wrap-history t)
(setq cider-repl-history-size 1000)
(setq cider-repl-history-file "~/.cider-repl-history")
如果您想要持久的历史记录,则需要

cider-repl-history-file
。如果您使用相对路径,历史记录将位于当前项目的本地。


0
投票

Cider 文档的 REPL History Browser 部分描述了

cider-repl-history
命令。运行该命令将以特殊用途的
cider-repl-history-mode
模式列出以前的 REPL 命令,您可以在其中移动和选择命令。

cider-repl-history-mode
中,您可以运行
cider-repl-history-occur
,它会要求输入正则表达式,然后将命令历史记录输出限制为仅与正则表达式匹配的命令历史记录,请参阅此处

可以说,用户体验可能会更好 - 应该有一个命令允许直接搜索历史记录,而无需打开任何新的 Emacs 缓冲区,类似于 Bash 中的 cmd-R (reverse-i-search)。

© www.soinside.com 2019 - 2024. All rights reserved.