在 CentOS 命令行上启用 alt/ctrl + left/right

Rud*_*die 12 linux inputrc

我的主机最近更新到一个新的 CentOS,我一直在“个性化”它,现在我错过了一些东西。

在我的主页Ubuntu的服务器,我可以forward-wordbackward-wordALT+ RIGHT/ LEFT。我没有为此做任何事情。我也可以ALT+BACKSPACE删除一个词。

在我的新 CentOS 上,我可以执行ALT+ BACKSPACE,但我无法让ALT+ RIGHT/LEFT工作!ALT+ B/F工作,但那是不可接受的,因为它只适用于左边,ALT而且我的手指不是那么瘦。(右ALT+ B/F只打印“b”或“f”)

我试过将 /etc/inputrc 的一部分复制到 CentOS,但这没有任何作用。

ALT或者CTRL,我不在乎,但我真的需要一条捷径。最后一个 CentOS 没有它,但自从 Ubuntu 以来,我一直在 CentOS 上缺少它。

我的 CentOS /etc/inputrc

"\e[5C": forward-word
"\e[5D": backward-word
"\e[1;5C": forward-word
"\e[1;5D": backward-word
Run Code Online (Sandbox Code Playgroud)

我的 Ubuntu /etc/inputrc

"\e[1;5C": forward-word
"\e[1;5D": backward-word
"\e[5C": forward-word
"\e[5D": backward-word
"\e\e[C": forward-word
"\e\e[D": backward-word
Run Code Online (Sandbox Code Playgroud)

我什至不知道它们是什么意思!?[1;5C钥匙有什么用??

ter*_*don 14

多亏了你的问题,我终于做了一些阅读并增加了我的理解,干杯!

因此,一个非常好的信息来源是man readline. 各种inputrc文件中指定的键绑定控制 BASH readline 库的工作方式。根据 readline 联机帮助页,您可以使用符号键名或转义序列:

   Key Bindings
       The syntax for controlling key bindings in the inputrc file is
       simple.  All that is required is the name of  the  command  or
       the  text  of a macro and a key sequence to which it should be
       bound. The name may be specified in one of two ways: as a sym?
       bolic  key  name, possibly with Meta- or Control- prefixes, or
       as a key sequence.  The name and key sequence are separated by
       a  colon.  There can be no whitespace between the name and the
       colon.

       When using the form keyname:function-name or macro, keyname is
       the name of a key spelled out in English.  For example:

              Control-u: universal-argument
              Meta-Rubout: backward-kill-word
              Control-o: "> output"
Run Code Online (Sandbox Code Playgroud)

手册页还指出默认配置文件是~/.inputrc这样的,因此我建议将您的绑定放在那里。

如果您想使用普通字母键(例如Control- g),Control-g: forward-word效果很好。方向键更难。我试图找到箭头键的键,但失败了。我尝试过的 ( left-arrow, left, :left) 都没有工作,所以看起来我们被转义序列困住了。

不幸的是,终端模拟器之间的确切转义序列不同(这就是为什么您的 Ubuntu inputrc 有多行)。要找出您最喜欢的终端使用哪个转义序列,请运行read,然后键入您感兴趣的键序列。在terminator,xtermgnome-terminal, Control- 中Left给出:

$ read
^[[1;5D
Run Code Online (Sandbox Code Playgroud)

aterm

$ read
^[Od    <-- that is a capital O not a zero (0).
Run Code Online (Sandbox Code Playgroud)

通过一些实验,我发现^[[DLeft^[[1;5DControl- Left。第一个^[Esc键,我想在这里使用,表示转义序列

在任何情况下,绑定Control-Leftforward-word的方式,所有的作品中,我添加了这些行到我的~/inputrc

"\e[1;5D": backward-word
"\eOd": backward-word
Run Code Online (Sandbox Code Playgroud)

由于我还没有完全理解的原因,Control\ewhich should be代表Esc

~/.inputrc适用于上面列出的所有终端的最终文件是:

"\e[1;5D": backward-word
"\eOd": backward-word
"\e[1;5C": forward-word
"\eOc": forward-word
Run Code Online (Sandbox Code Playgroud)