Tmux 乱码修复:extended-keys 配置调整
您现在看到的**11;rgb:0c0c/0c0c/0c0c** 正是 tmux 在 attach(重新进入会话)时 主动向终端发送 OSC 11 查询(查询背景颜色),终端回复后 tmux 没有及时“吃掉”这个回复,导致它泄漏到 shell 的输入缓冲区里。
这是 tmux 3.4+(Debian 13 自带 3.5a)引入的特性导致的已知问题(GitHub 上很多 issue 都在报,包括 #4535),目前 tmux 官方还没有彻底修复。
最有效的解决办法(按顺序尝试)
第 1 步:修改 ~/.tmux.conf(推荐一次性加全)
把配置文件改成下面这样(保留您原来的 mouse 和 extended-keys):
# 基础设置
set -g mouse on
set -g default-terminal "tmux-256color"
# 正确的 server options
set -s extended-keys on
set -s extended-keys-format csi-u
set -as terminal-features "*:extkeys,RGB"
# 关键修复:让 tmux 有足够时间处理 OSC 颜色查询回复
set -s escape-time 300
# 强制告诉 tmux 终端支持真彩色,减少查询问题
set -ag terminal-overrides ",*:RGB"
保存后重新加载配置(在 tmux 里面按 Ctrl+b : 然后输入):
source-file ~/.tmux.conf
第 2 步:测试
- detach(
Ctrl+b d) - 重新 attach(
tmux attach) - 看输入框是否还出现
11;rgb:...
应急清理(每次出现时)
在出现乱码的输入行直接按:
Ctrl + U(清空当前行,最快)
或输入 reset 回车重置终端。