提到的人readline是对的。
您可以使用命令编辑绑定bind(尝试help bind)。
对于这个特定问题,让我们看看 Control-R 绑定了什么:
\n\n$ bind -P |grep C-r\nre-read-init-file can be found on "\\C-x\\C-r".\nreverse-search-history can be found on "\\C-r".\nrevert-line can be found on "\\M-\\C-r".\nRun Code Online (Sandbox Code Playgroud)\n\n好的。其中之一\\C-r就是 Control-R。让我们仔细检查一下:
$ bind -q reverse-search-history\nreverse-search-history can be invoked via "\\C-r".\nRun Code Online (Sandbox Code Playgroud)\n\nman readline包括:
reverse-search-history (C-r)\n Search backward starting at the current line and moving `up\'\n through the history as necessary. This is an incremental\n search.\n
看起来不错。我们如何改变它?假设您想使用 \xe2\x8c\x98-B 代替。这就是\\M-breadline 中的 Meta-b(又名 )。
让我们尝试一下:
\n\n$ bind \'\\M-b:reverse-search-history\'\n$ bind -q reverse-search-history\nreverse-search-history can be invoked via "\\C-r", "\\M-b".\nRun Code Online (Sandbox Code Playgroud)\n\n现在按 \xe2\x8c\x98-b 会像 Control-R 一样触发反向搜索。但 Control-R 仍处于绑定状态。我们可以解决这个问题:
\n\n$ bind -r \'\\C-r\'\n$ bind -q reverse-search-history\nreverse-search-history can be invoked via "\\M-b".\nRun Code Online (Sandbox Code Playgroud)\n\n此更改将在当前 shell 会话中保留,但会在下次调用 shell 时消失。要使更改持久,请执行以下操作:
\n\n$ echo \'"\\M-b": reverse-search-history\' >> ~/.inputrc\nRun Code Online (Sandbox Code Playgroud)\n\n现在~/.inputrc包含所需的绑定。任何使用它进行readline配置的程序(包括您的 shell)现在都将使用您指定的绑定。
| 归档时间: |
|
| 查看次数: |
4484 次 |
| 最近记录: |