vi 命令行编辑插入模式覆盖

vi 命令行编辑插入模式覆盖

我在 Ubuntu 下的 bash shell 中使用 Windows 终端(TERM=xterm-256color):

uname -a
Linux xxxxxxx 4.19.128-microsoft-standard #1 SMP Tue Jun 23 12:58:10 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

我正在使用 vi 命令行编辑模式(在两个系统上的 .bashrc 中设置 -o vi),一切都按预期工作。

当我 ssh 到一台 bsd 机器时:

uname -a
FreeBSD yyyyyyy 11.1-RELEASE FreeBSD 11.1-RELEASE #0: Fri Apr 20 14:32:29 EDT 2018     root@zzzzzzz:/usr/obj/usr/src/sys/BBKERN  amd64 

插入模式不再按预期工作。在插入模式下,它不是向右推文本,而是覆盖文本。但是,当命令被处理时(即我按下回车键),很明显文本已被插入,而不是被覆盖。

通过环顾四周,我猜这是我要在 .inputrc 中解决的问题(?)不幸的是,我不知道如何获取 Win Terminal 发送的或 BSD 想要的键值。

我会注意到插入在 vi 编辑器中按预期工作。

有人知道我该如何修复这个问题或者如何获取预期的密钥代码吗?

答案1

好的,把这个问题追溯到相当简单的事情上。我使用的是 $TERM =“xterm”。将其更改为“rxvt”解决了这个问题。显然,这两种终端类型的终端功能定义有所不同。深入研究术语信息页面上我找到了 'ich1' 代码。测试后我发现:

> uname -a;echo $TERM
Linux d10c167 4.19.128-microsoft-standard #1 SMP Tue Jun 23 12:58:10 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
rxvt-unicode
> tput smir|od -ba;tput rmir|od -ba;tput ich1|od -ba
0000000 033 133 064 150
        esc   [   4   h
0000004
0000000 033 133 064 154
        esc   [   4   l
0000004
0000000 033 133 100
        esc   [   @
0000003


> uname -a;export TERM="xterm";echo $TERM
Linux d10c167 4.19.128-microsoft-standard #1 SMP Tue Jun 23 12:58:10 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
xterm
> tput smir|od -ba;tput rmir|od -ba;tput ich1|od -ba
0000000 033 133 064 150
        esc   [   4   h
0000004
0000000 033 133 064 154
        esc   [   4   l
0000004
0000000


name -a;echo $TERM
FreeBSD xxxx.yyyy.zzz.com 11.1-RELEASE FreeBSD 11.1-RELEASE #0: Fri Apr 20 14:30:50 EDT 2018
rxvt-unicode
>  tput im|od -ba;tput ei|od -ba;tput ic|od -ba
0000000   033 133 064 150
          esc   [   4   h
0000004
0000000   033 133 064 154
          esc   [   4   l
0000004
0000000   033 133 100
          esc   [   @
0000003


> uname -a;echo $TERM
FreeBSD xxxx.yyyy.zzz.com 11.1-RELEASE FreeBSD 11.1-RELEASE #0: Fri Apr 20 14:30:50 EDT 2018
xterm
tput im|od -ba;tput ei|od -ba;tput ic|od -ba
0000000   033 133 064 150
          esc   [   4   h
0000004
0000000   033 133 064 154
          esc   [   4   l
0000004

来自上述链接:

   Terminfo  can  describe both terminals which have an insert mode, and
   terminals which send a simple sequence to open a  blank  position  on
   the current line.  Give as smir the sequence to get into insert mode.
   Give as rmir the sequence to leave insert mode.  Now give as ich1 any
   sequence  needed  to  be sent just before sending the character to be
   inserted.  Most terminals with a true insert mode will not give ich1;
   terminals which send a sequence to open a screen position should give
   it here.

在我的例子中,Ubuntu 上的 terminfo 支持 smir、rmir 和 ich1。然而在 FreeBSD 机器上术语表定义了 im、ei,但没有定义 ic。看起来它应该可以工作,但它显然需要 ic,而它却没有。有趣的是,如果我从 FreeBSD 命令行运行 xterm&(xterm 应用程序),它会报告为 TERM="xterm",并且插入工作如预期的那样。

因此,如果您发现自己处于类似情况,请查看您使用的终端是否支持给定操作系统和终端的正确插入代码。

相关内容