简体   繁体   English

使 Ctrl-p 和 Ctrl-n 搜索按键入字符过滤的 shell 历史记录

[英]Make Ctrl-p and Ctrl-n search the shell history filtered by typed characters

I love that emacs key bindings also work in the ubuntu shell by default.我喜欢 emacs 键绑定默认情况下也适用于 ubuntu shell。 However, I would also like to have those two keys partially search through the shell history but filtered based on what was already typed in. If enabled in /etc/inputrc, the normal page up and page down keys do just that, but I don't have those keys and thus would like to use Ctrl-p and Ctrl-n for that as well.但是,我还想让这两个键部分搜索 shell 历史记录,但根据已经输入的内容进行过滤。如果在 /etc/inputrc 中启用,正常的向上翻页和向下翻页键就是这样做的,但我没有'没有这些键,因此也想使用 Ctrl-p 和 Ctrl-n 。 I have seen this working in the zshell but I am using bash.我已经看到这在 zshell 中工作,但我使用的是 bash。 How can I achieve that?我怎样才能做到这一点?

To use the typed string as a prefix for searching forward/backward in the history, add the following bindings to your ~/.inputrc要将键入的字符串用作在历史记录中向前/向后搜索的前缀,请将以下绑定添加到您的 ~/.inputrc

"\C-p": history-search-backward
"\C-n": history-search-forward

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM