Bash 可以配置为在当前输入行上搜索字符串吗?
用于在使用命令行时快速定位位置(是的,我是 Emacs 粉丝)。看了Bash的man后,我找不到这样的提示。是否需要修改readline的源代码来支持这一点?
非常感谢!!
For fast locating positions when using the command line(Yes, I'm an Emacs fan). After viewing Bash' man, I can't find such tips. Does it need to modify readline's source code to support this?
Thank you very much!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道有什么方法可以直接在命令行中执行此操作,但 bash 确实支持按键,可以在您选择的编辑器中打开命令行。来自 bash 联机帮助页:
因此,在 emacs 绑定模式(默认)下按 CTRL-x CTRL-e 或在 vi 绑定模式下按 ESC v(
set -o vi
)将打开现有命令行由上面提到的环境变量指定的编辑器。您可以编辑命令行,保存并退出编辑器后,命令将被执行。I don't know of a way to do it directly in the command line, but bash does support a keypress that will open the command line in your editor of choice. From the bash manpage:
So hitting CTRL-x CTRL-e in emacs bindings mode (the default) or ESC v in vi bindings mode (
set -o vi
for that) will open the existing command line in the editor specified by the environment variables mentioned above. You can edit the command line, and once you save and quit the editor the command will be executed.CTRL-r(反向-i-搜索)将允许您搜索当前行以及历史记录中的任何内容。
如果您想跳回几个参数,可以按空格键,然后再次按 CTRL-r 来“再次查找”。 Escape 会将光标移至最后一个搜索结果处。
CTRL-r (reverse-i-search) will allow you to search the current line as well as anything in your history.
If you want to jump back a couple of arguments, you can hit space, then CTRL-r again to "find again". Escape will break out of it with the cursor at the last search result.