Bash 可以配置为在当前输入行上搜索字符串吗?

发布于 2024-08-06 20:31:19 字数 101 浏览 1 评论 0原文

用于在使用命令行时快速定位位置(是的,我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故乡的云 2024-08-13 20:31:19

我不知道有什么方法可以直接在命令行中执行此操作,但 bash 确实支持按键,可以在您选择的编辑器中打开命令行。来自 bash 联机帮助页:

   edit-and-execute-command (C-xC-e)
          Invoke  an  editor  on the current command line, and execute the
          result as shell commands.   Bash  attempts  to  invoke  $FCEDIT,
          $EDITOR, and emacs as the editor, in that order.

因此,在 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:

   edit-and-execute-command (C-xC-e)
          Invoke  an  editor  on the current command line, and execute the
          result as shell commands.   Bash  attempts  to  invoke  $FCEDIT,
          $EDITOR, and emacs as the editor, in that order.

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.

戏蝶舞 2024-08-13 20:31:19

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文