tmux - 为每个命令强制重复前缀键

tmux - Force repeat prefix key for every command

现在我的 tmux 键绑定设置为前缀 + h/j/k/l(即 vim 样式绑定)用于移动窗格的焦点 left/down/up/right。但是,有时当我切换到窗格 运行 vim 并立即开始使用 h/j/k/l 导航时,我会卡在 "tmux mode" 中,它将继续切换窗格而不是导航vim。切换到普通终端窗格并列出文件时(即使用 "l"),我遇到了类似的问题。为了避免这种情况,我想强制 tmux 为我所做的每个窗格切换都要求前缀键。

有办法吗?

编辑: 如果需要,这是我的 .tmux.conf

# Bind CTRL+a to the prefix button
set -g prefix C-a
unbind C-b
bind C-a send-prefix
bind a send-prefix
# Remove the delay of escape key
set -s escape-time 0
# Bind PREFIX + r to reload the .conf file
unbind r
bind r source-file ~/.tmux.conf
# Quick pane cycling
unbind ^A
bind ^A select-pane -t :.+

set -g base-index 1
setw -g pane-base-index 1

set-option -g default-shell "/bin/bash"
# List of tmux plugins
set -g @plugin 'tmux-plugins/tmux-resurrect'
# Plugin manager
run '~/.tmux/plugins/tpm/tpm'
# Enable mouse support on tmux
set -g mouse on
# Rebind the pane switching to vim-like shortcuts
bind -r k select-pane -U
bind -r j select-pane -D
bind -r h select-pane -L
bind -r l select-pane -R
unbind Up
unbind Down
unbind Left
unbind Right
unbind C-Up
unbind C-Down
unbind C-Left
unbind C-Right
# Set the tmux colors to default
set -g default-terminal screen-256color

这是因为您在为 h/j/k/l 创建键绑定时使用了 -r

来自 tmux 手册页中 bind-key 的条目:

The -r flag indicates this key may repeat, see the repeat-time option.

关于 repeat-time 选项:

Allow multiple commands to be entered without pressing the prefix-key again in the specified time milliseconds (the default is 500). Whether a key repeats may be set when it is bound using the -r flag to bind-key. Repeat is enabled for the default keys bound to the resize-pane command.

只需从这四个命令中删除 -r 即可让它每次都需要前缀键。

我不同意@filbranden 的断言“每个窗格开关都需要前缀是正常行为”。这显然是错误的:在全新安装中,您可以创建一个带有两个窗格的 window,键入前缀 (C-b),然后通过按箭头键在窗格之间跳转任意次。

This answer on StackExchange 似乎是正确的。导致不需要前缀的功能通过设置选项 repeat-time 来控制。默认设置为 500(这就是默认行为不需要前缀的原因)。

要禁用此行为,只需将此行添加到您的配置中:

set-option -g repeat-time 0