tmux 鼠标复制模式跳到底部

tmux mouse copy-mode jumps to bottom

我在 ssh 会话中使用 tmux。 我正在使用多个窗格和 windows.

我启用了鼠标模式,到目前为止效果很好。

当我输入 select 文本时,它会自动复制到 tmux 缓冲区,然后 window 跳转到末尾。 所以如果我向上滚动并点击它跳到最后的东西...... 当我在窗格之间切换时,会触发复制命令并且输出结束。 我真的不喜欢这种行为,我宁愿必须按一个按钮进行复制或单击 q 完成复制模式或其他操作。

是否可以禁用自动复制 // 在鼠标按钮释放时自动跳转到末尾?

我在服务器上通过 ssh 运行 tmux 2.0。在客户端的终结者中。

# config                                                                        
#{{{                                                                            
                                                                                
# 0 is too far from ` ;)                                                        
set -g base-index 1                                                             
                                                                                
# Automatically set window title                                                
# set-window-option -g automatic-rename on                                      
# set-option -g set-titles on                                                   
                                                                                
set -g default-terminal screen-256color                                         
set -g history-limit 10000                                                      
                                                                                
set -g status-keys vi                                                           
setw -g mode-keys vi                                                            
setw -g mode-mouse on                                                           
set -g mouse-select-window on                                                   
set -g mouse-select-pane on                                                     
set -g mouse-resize-pane on                                                     
                                                                                
# No delay for escape key press                                                 
set -sg escape-time 0                                                           
                                                                                
#}}}                                                                            
                                                                                
# bind keys                                                                     
#{{{                                                                            
# Reload tmux config                                                            
bind r source-file ~/.tmux.conf                                                 
                                                                                
# remap prefix to Control + a                                                      
set -g prefix C-a                                                                  
# bind 'C-a C-a' to type 'C-a'                                                     
bind C-a send-prefix                                                               
unbind C-b                                                                         
                                                                                   
# switch tabs with <b n>                                                           
bind b previous-window                                                             
                                                                                   
# vi like paste                                                                    
bind-key p paste-buffer                                                            
                                                                                   
# quick pane cycling                                                               
unbind a                                                                           
bind a select-pane -t :.+                                                          
                                                                                   
bind-key v split-window -h                                                         
bind-key s split-window -v                                                         
                                                                                   
bind-key J resize-pane -D 10                                                       
bind-key K resize-pane -U 10                                                       
bind-key H resize-pane -L 10                                                       
bind-key L resize-pane -R 10                                                       
                                                                                   
bind-key M-j resize-pane -D 2                                                      
bind-key M-k resize-pane -U 2                                                      
bind-key M-h resize-pane -L 2                                                      
bind-key M-l resize-pane -R 2                                                      
                                                                                   
# Vim style pane selection                                                         
bind h select-pane -L                                                              
bind j select-pane -D                                                              
bind k select-pane -U        
bind -n M-Down select-pane -D                                                   
                                                                                
# find asci keycodes with "sudo showkey -a" - works only tmux >1.7              
# us-keyboard like [ ]                                                          
bind-key -r 0xc3 display 'c3 prefix binding hack'                               
bind-key -r 0xb6 copy-mode # ö                                                  
bind-key -r 0xa3 paste-buffer # ä                                               
# us { }                                                                        
bind-key -r 0x96 swap-pane -U # Ö - swap pane to prev position                  
bind-key -r 0x84 swap-pane -D # Ä - to next pos  
                               
#}}}                         



       

看起来升级到 tmux 2.1 可能会解决您的问题。

In version 2.1 they changed mouse-mode, mouse-select-window/pane etc with single mouse switch. Mouse actions now generates key events that can be mapped as ordinary keys.

通过将以下内容添加到我的 ~/.tmux.conf

,我能够让鼠标选择停止跳转到 tmux(版本 2.2)的底部
setw -g mouse on
setw -g mode-keys vi
unbind -t vi-copy MouseDragEnd1Pane

注意:这有打开 vi 模式的副作用。

我找到了 this issue to be relevant, and found the configuration above in these dotfiles

从 tmux 2.2 开始,功能 copy-selection -x 可用。选择以下选项后,tmux 将保持复制模式。选择适合您模式设置的模式。

bind-key -t vi-copy MouseDragEnd1Pane copy-selection -x
bind-key -t emacs-copy MouseDragEnd1Pane copy-selection -x

从 tmux 2.5 开始,您应该使用

unbind -T copy-mode-vi MouseDragEnd1Pane

以下对我有用。感谢 github 上的 @stagebind

对于 vi 模式配置,https://github.com/tmux/tmux/issues/140#issuecomment-321144647:

unbind -T copy-mode-vi MouseDragEnd1Pane

对于非 vi 模式配置,https://github.com/tmux/tmux/issues/140#issuecomment-302742783:

# 2.4+
unbind -T copy-mode MouseDragEnd1Pane
# 2.2 - 2.3
unbind -t vi-copy MouseDragEnd1Pane

我花了一些时间才得到正确答案。

我也在使用 Alacritty,无法在鼠标 select 上启用复制,因为 MouseDragEnd1Pane 存在问题,如 https://github.com/jwilm/alacritty/issues/1002 中所述。

用鼠标选择文本,然后如果我需要使用键 y 复制它,我可以使用此配置:

bind -T copy-mode-vi y send -X copy-pipe "reattach-to-user-namespace pbcopy"\; display-message "copied to system clipboard"

使用鼠标和 vi 键绑定支持进行复制和粘贴的完整配置如下所示:

set-option -g default-command "reattach-to-user-namespace -l bash"
set -g mouse on

bind P paste-buffer
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind -T copy-mode-vi y send -X copy-pipe "reattach-to-user-namespace pbcopy"\; display-message "copied to system clipboard"
bind-key -T copy-mode-vi r send-keys -X rectangle-toggle

## don't jump to bottom on mouse select - when vi-mode enabled - 2.4+
#unbind -T copy-mode MouseDragEnd1Pane
## don't jump to bottom on mouse select - when vi-mode enabled - 2.2 - 2.3
#unbind -t vi-copy MouseDragEnd1Pane
## don't jump to bottom on mouse select - when vi-mode enabled
unbind -T copy-mode-vi MouseDragEnd1Pane

我正在使用 OS X.

我想说现在最简单的方法就是使用 tmux-yank plugin and add the yank_action configuration option:

# ~/.tmux.conf

set -g @yank_action 'copy-pipe' # or 'copy-pipe-and-cancel' for the default

此外,tmux-yank 还为您管理 OS 剪贴板(Linux、macOS、WSL)之间的差异,并添加了一些非常有用的快捷方式来复制当前命令行内容和 cwd。强烈推荐。