有没有办法在 tmux 中实现“snapback”?

有没有办法在 tmux 中实现“snapback”?

我是否可以进行配置tmux,以便一旦进入回滚,开始键入新命令(例如任何字母,但任何可打印字符也可以)将退出回滚并将该字母传递给会话?就像 PuTTY 的“按键时重置滚动”选项或其他终端中的类似选项一样。

答案1

找到了答案。可能不是最好的答案,但它有效。技巧是将copy-mode表中所有未修改的键绑定到 1) 取消复制模式和 2) 将其自身发送到会话。所以在tmux.conf

bind-key -T copy-mode a send-keys -X cancel \; send-keys a
bind-key -T copy-mode b send-keys -X cancel \; send-keys b
bind-key -T copy-mode c send-keys -X cancel \; send-keys c
bind-key -T copy-mode d send-keys -X cancel \; send-keys d
bind-key -T copy-mode e send-keys -X cancel \; send-keys e
bind-key -T copy-mode f send-keys -X cancel \; send-keys f
bind-key -T copy-mode g send-keys -X cancel \; send-keys g
bind-key -T copy-mode h send-keys -X cancel \; send-keys h
bind-key -T copy-mode i send-keys -X cancel \; send-keys i
bind-key -T copy-mode j send-keys -X cancel \; send-keys j
bind-key -T copy-mode k send-keys -X cancel \; send-keys k
bind-key -T copy-mode l send-keys -X cancel \; send-keys l
bind-key -T copy-mode m send-keys -X cancel \; send-keys m
bind-key -T copy-mode n send-keys -X cancel \; send-keys n
bind-key -T copy-mode o send-keys -X cancel \; send-keys o
bind-key -T copy-mode p send-keys -X cancel \; send-keys p
bind-key -T copy-mode q send-keys -X cancel \; send-keys q
bind-key -T copy-mode r send-keys -X cancel \; send-keys r
bind-key -T copy-mode s send-keys -X cancel \; send-keys s
bind-key -T copy-mode t send-keys -X cancel \; send-keys t
bind-key -T copy-mode u send-keys -X cancel \; send-keys u
bind-key -T copy-mode v send-keys -X cancel \; send-keys v
bind-key -T copy-mode w send-keys -X cancel \; send-keys w
bind-key -T copy-mode x send-keys -X cancel \; send-keys x
bind-key -T copy-mode y send-keys -X cancel \; send-keys y
bind-key -T copy-mode z send-keys -X cancel \; send-keys z

等等。您必须单独映射每个键,包括大写/小写变体。

编写了一个 Python 脚本 ( snapback.py) 来编写所有这些行:

import string

for c in string.printable:
    if ord(c) > 31:     # printable contains control chars we don't want
        c = repr(c).replace(r"\\", "\\").replace(r";", r"\;")
        print('bind-key -T copy-mode', c,
              'send-keys -X cancel \; send-keys', c.replace(";", r"\;"))

用法:

python snapback.py >> ~/.tmux.conf

相关内容