退格键在 tmux 命令提示符下不起作用
Backspace not working in tmux command prompt
我在 tmux 命令提示符下使用 Backspace 键时遇到问题。退格键会删除 tmux 中的先前字符(如预期的那样),但不会删除 tmux 命令提示符中的字符。例如,<PREFIX>:lists<DEL>
不会删除 's' 字符。在这种情况下,使用 C-h
而不是 Delete 键 会 删除 's' 字符。 C-?
不会删除 's' 字符。我在 tmux window:
中进行了一些调试
$TERM=screen-256color
infocmp reports kbs=7 (good)
appres XTerm | grep backarrowKeyIsErase reports as true (good)
appres XTerm | grep ptyInitialErase reports as true (good)
stty -a | grep erase reports as "^H" (bad, I think I want ^?)
我也试过将 .tmux.conf
中的退格键绑定到 C-h
和 C-?
,但都不起作用。 :list-keys
在 tmux 中确认映射正在发生。
bind-key -n BSpace send-keys C-?
我在调用 tmux
之前和之后也做了一个 stty erase ^?
,这不会影响行为。最后,我完全删除了我的 .tmux.conf
并且仍然得到相同的行为。
命令行是否使用会影响 BSpace 功能的不同键绑定集?
问题是因为我的 $TERM
设置、我的 .Xdefaults
、终端的键绑定(我使用 konsole
)和任何 tmux
之间不匹配正在发送。我的具体修复要求在任何地方都将 Backspace 设置为 ^?
而不是 ^h
。此外,tmux 的 $TERM
最好设置为 screen-256colors 或 tmux-256colors,因此您需要确保这些终端模式可以看到正确的键映射。
在我的 .Xdefaults
中,请注意这是针对所有 VT100 而不仅仅是 XTerm*VT100 因为我希望屏幕、tmux 和 konsole 看到这些条目:
*VT100.Translations: #override \n\
<Key>BackSpace: string(0x7F) \n\
<Key>Delete: string("3[3~")
*ttyModes: erase ^?
我还必须修复 ~/.cshrc
中的绑定密钥:
bindkey -a "\e[3~" delete-char
stty erase ^?
... 并向 ~/.inputrc
文件(konsole 读取)添加类似的条目:
"\e[3~": delete-char
正如我从 Backspace bad behaviour #321 得到的:
I had the same problem (with backspace plus getting addition characters from auto completion) whenever I entered a tmux session. I removed the .tmux.conf and the problem disappeared so I changed the following in my .tmux.conf
changed from: set -g default-terminal "tmux-256color" to: set -g
default-terminal "xterm-256color"
This solved the problem. Removing this line altogether also worked but
it seemed better to be explicit.
对我有用。
注意:更改设置后,您可能需要 运行
tmux kill-server
使更改生效。
对我来说,退格键在 vim 中有效,但在 vim + tmux 中无效。 This answer from SuperUser 已修复:
You can map the backspace key to what you need, like Kevin said. It looks like you need to map it to ^? (rather than ^H)
To do that, use the following command:
stty erase "^?"
This can be added to your startup scripts (.login or .tcshrc or .bashrc, or other files, depending on which shell you use).
很多答案都不适合我,但我终于找到了适用于 MacO 的 Gist。这里的重点是 RGB 颜色,但我认为当 .tmux.conf
中使用 set-option default-terminal "screen-256color"
时,颜色关闭和退格不起作用的根本原因是您的计算机缺少有关 [=21 的一些信息=] 您必须手动安装的终端。与在不同的配置文件中到处添加代码行并祈祷一切正常相比,这是一个更强大、更全面的解决方案。
https://gist.github.com/bbqtd/a4ac060d6f6b9ea6fe3aabe735aa9d95
想法是 MacOS 自然没有最新的 ncurses program/doesn没有对 tmux 终端的正确描述所以你必须自己下载并安装它。这些步骤直接取自要点:
确保 tic
(用于安装终端信息的工具)位于 /usr/bin
:
$ which tic
/usr/bin/tic
在我的例子中不是这样,所以我添加了
export PATH="/usr/bin:$PATH"
给我的 .zshrc
获取终端描述:
$ curl -LO https://invisible-island.net/datafiles/current/terminfo.src.gz && gunzip terminfo.src.gz
安装它们(如果您想为所有用户安装它们(以 root 用户身份(通过在前面加上 sudo
)):
$ /usr/bin/tic -xe tmux-256color terminfo.src
$ sudo /usr/bin/tic -xe tmux-256color terminfo.src
这个错误:
"terminfo.src", line 1650, terminal 'pccon+base': enter_bold_mode but no exit_attribute_mode
"terminfo.src", line 1650, terminal 'pccon+base': enter_reverse_mode but no exit_attribute_mode
不用担心。
现在
infocmp -x tmux-256color
应该显示一些输出
然后添加
set-option default-terminal "tmux-256color"
到~/.tmux.conf
.
确保至少没有丢失以下输出之一:
$ tmux info | grep -e RGB -e Tc
如果它们都丢失了,您必须执行以下三项之一:
set-option -a terminal-overrides ",XXX:RGB"
set-option -a terminal-overrides ",*256col*:RGB"
set-option -a terminal-overrides ",alacritty:RGB"
其中 xxx 类似于 xterm-256color(您的终端类型),星号进行模式匹配,最后一个认识到它可能是其他东西(我的是 xterm-kitty
)但我不是确定要放在这里的确切内容,因为我为 Tc 所做的 ```grep``s 返回了 true。
好的,应该做到了!代码直接取自 Gist,因此所有功劳归于作者。将它包括在这里以防 Gist 以某种方式被删除。
我在 tmux 命令提示符下使用 Backspace 键时遇到问题。退格键会删除 tmux 中的先前字符(如预期的那样),但不会删除 tmux 命令提示符中的字符。例如,<PREFIX>:lists<DEL>
不会删除 's' 字符。在这种情况下,使用 C-h
而不是 Delete 键 会 删除 's' 字符。 C-?
不会删除 's' 字符。我在 tmux window:
$TERM=screen-256color
infocmp reports kbs=7 (good)
appres XTerm | grep backarrowKeyIsErase reports as true (good)
appres XTerm | grep ptyInitialErase reports as true (good)
stty -a | grep erase reports as "^H" (bad, I think I want ^?)
我也试过将 .tmux.conf
中的退格键绑定到 C-h
和 C-?
,但都不起作用。 :list-keys
在 tmux 中确认映射正在发生。
bind-key -n BSpace send-keys C-?
我在调用 tmux
之前和之后也做了一个 stty erase ^?
,这不会影响行为。最后,我完全删除了我的 .tmux.conf
并且仍然得到相同的行为。
命令行是否使用会影响 BSpace 功能的不同键绑定集?
问题是因为我的 $TERM
设置、我的 .Xdefaults
、终端的键绑定(我使用 konsole
)和任何 tmux
之间不匹配正在发送。我的具体修复要求在任何地方都将 Backspace 设置为 ^?
而不是 ^h
。此外,tmux 的 $TERM
最好设置为 screen-256colors 或 tmux-256colors,因此您需要确保这些终端模式可以看到正确的键映射。
在我的 .Xdefaults
中,请注意这是针对所有 VT100 而不仅仅是 XTerm*VT100 因为我希望屏幕、tmux 和 konsole 看到这些条目:
*VT100.Translations: #override \n\
<Key>BackSpace: string(0x7F) \n\
<Key>Delete: string("3[3~")
*ttyModes: erase ^?
我还必须修复 ~/.cshrc
中的绑定密钥:
bindkey -a "\e[3~" delete-char
stty erase ^?
... 并向 ~/.inputrc
文件(konsole 读取)添加类似的条目:
"\e[3~": delete-char
正如我从 Backspace bad behaviour #321 得到的:
I had the same problem (with backspace plus getting addition characters from auto completion) whenever I entered a tmux session. I removed the .tmux.conf and the problem disappeared so I changed the following in my .tmux.conf
changed from: set -g default-terminal "tmux-256color" to: set -g default-terminal "xterm-256color"
This solved the problem. Removing this line altogether also worked but it seemed better to be explicit.
对我有用。 注意:更改设置后,您可能需要 运行
tmux kill-server
使更改生效。
对我来说,退格键在 vim 中有效,但在 vim + tmux 中无效。 This answer from SuperUser 已修复:
You can map the backspace key to what you need, like Kevin said. It looks like you need to map it to ^? (rather than ^H)
To do that, use the following command:
stty erase "^?"
This can be added to your startup scripts (.login or .tcshrc or .bashrc, or other files, depending on which shell you use).
很多答案都不适合我,但我终于找到了适用于 MacO 的 Gist。这里的重点是 RGB 颜色,但我认为当 .tmux.conf
中使用 set-option default-terminal "screen-256color"
时,颜色关闭和退格不起作用的根本原因是您的计算机缺少有关 [=21 的一些信息=] 您必须手动安装的终端。与在不同的配置文件中到处添加代码行并祈祷一切正常相比,这是一个更强大、更全面的解决方案。
https://gist.github.com/bbqtd/a4ac060d6f6b9ea6fe3aabe735aa9d95
想法是 MacOS 自然没有最新的 ncurses program/doesn没有对 tmux 终端的正确描述所以你必须自己下载并安装它。这些步骤直接取自要点:
确保 tic
(用于安装终端信息的工具)位于 /usr/bin
:
$ which tic
/usr/bin/tic
在我的例子中不是这样,所以我添加了
export PATH="/usr/bin:$PATH"
给我的 .zshrc
获取终端描述:
$ curl -LO https://invisible-island.net/datafiles/current/terminfo.src.gz && gunzip terminfo.src.gz
安装它们(如果您想为所有用户安装它们(以 root 用户身份(通过在前面加上 sudo
)):
$ /usr/bin/tic -xe tmux-256color terminfo.src
$ sudo /usr/bin/tic -xe tmux-256color terminfo.src
这个错误:
"terminfo.src", line 1650, terminal 'pccon+base': enter_bold_mode but no exit_attribute_mode
"terminfo.src", line 1650, terminal 'pccon+base': enter_reverse_mode but no exit_attribute_mode
不用担心。
现在
infocmp -x tmux-256color
应该显示一些输出 然后添加
set-option default-terminal "tmux-256color"
到~/.tmux.conf
.
确保至少没有丢失以下输出之一:
$ tmux info | grep -e RGB -e Tc
如果它们都丢失了,您必须执行以下三项之一:
set-option -a terminal-overrides ",XXX:RGB"
set-option -a terminal-overrides ",*256col*:RGB"
set-option -a terminal-overrides ",alacritty:RGB"
其中 xxx 类似于 xterm-256color(您的终端类型),星号进行模式匹配,最后一个认识到它可能是其他东西(我的是 xterm-kitty
)但我不是确定要放在这里的确切内容,因为我为 Tc 所做的 ```grep``s 返回了 true。
好的,应该做到了!代码直接取自 Gist,因此所有功劳归于作者。将它包括在这里以防 Gist 以某种方式被删除。