Tmux 键绑定问题

Tmux 键绑定问题

不久前,我从使用 screen 切换到使用 tmux。我有一个 tmux 配置,它使用 screen 的Ctrl+a序列,而不是 tmux 的默认Ctrl+ b

但是,我发现一个问题,如果我按下 ctrl-a 然后按 p 进入上一个屏幕,或按 n 进入下一个屏幕,而不释放 ctrl 键,tmux 会忽略按键顺序。如果我按下Ctrl+ a,释放Ctrl,然后按np,它就可以正常工作。

有什么想法可能出了什么问题吗?我的配置如下:

# $Id: t-williams.conf,v 1.1 2009/11/02 18:59:28 nicm Exp $
#
# ~/.tmux.conf - tmux terminal multiplexer config
# Thayer Williams (http://cinderwick.ca)
# "Feel free to do whatever you like with it."

# set prefix key to ctrl+a
unbind C-b
set -g prefix C-a

# send the prefix to client inside window (ala nested sessions)
bind-key a send-prefix

# toggle last window like screen
bind-key C-a last-window

# confirm before killing a window or the server
bind-key k confirm kill-window
bind-key K confirm kill-server

# toggle statusbar
bind-key b set-option status

# ctrl+left/right cycles thru windows
bind-key -n C-right next
bind-key -n C-left prev

# open a man page in new window
bind / command-prompt "split-window 'exec man %%'"

# switch split window keys
unbind %
bind | split-window -h
bind - split-window -v

# quick view of processes
bind '~' split-window "exec htop"

# scrollback buffer n lines
set -g history-limit 10000

# listen for activity on all windows
#set -g bell-action any
setw -g monitor-activity off
set -g visual-activity off

# on-screen time for display-panes in ms
set -g display-panes-time 2000

# start window indexing at one instead of zero
set -g base-index 1

# enable wm window titles
set -g set-titles on

# Automatically set window title
setw -g automatic-rename

# statusbar --------------------------------------------------------------

set -g display-time 2000

# default statusbar colors
set -g status-fg white
set -g status-bg cyan
set -g status-attr default

# default window title colors
set-window-option -g window-status-fg black
set-window-option -g window-status-bg cyan
set-window-option -g window-status-attr default

# active window title colors
set-window-option -g window-status-current-fg white
set-window-option -g window-status-current-bg black
set-window-option -g window-status-current-attr bright

# command/message line colors
set -g message-fg blue
set -g message-bg white
set -g message-attr dim

# center align the window list
set -g status-justify centre

# show some useful 
set -g status-left "[#[fg=black]#H#(uptime | cut -d ',' -f 3- | sed -e 's/ load average: //' | sed -e 's/  / /g')#[default]]"
set -g status-left-length 50
set -g status-right "[#[fg=black]%a %Y-%m-%d %H:%M#[default]]"
set -g status-right-length 50

set -g default-terminal "screen"

答案1

我找到了模拟屏幕下原始行为的解决方案(仅包括配置的相关部分,其余部分只是表面文章):

# set prefix key to ctrl+a until I have time to adapt
unbind C-b
set -g prefix C-a

# send the prefix to client inside window (ala nested sessions)
bind-key a send-prefix

# toggle last window like screen
bind-key C-a last-window

# navigate through windows like screen
bind-key C-a-n next
bind-key C-a-p prev

直接将按键序列链接在一​​起是解决方案。我没有意识到你实际上可以这样做,但它工作得很好,而且我仍然可以保留发送前缀选项(我担心这是问题的一部分)。

答案2

Tmux 认为按住 ctrl 键时执行的任何按键都是 C- 形式。不过,您只需添加bind C-p prevbind C-n next即可获得相同的效果。

相关内容