使用鼠标在tmux中恢复旧的复制粘贴行为

问题描述 投票:89回答:9

这就是我以前在tmux中复制粘贴所做的事情(使用鼠标,键盘的工作方式不同,这不是我感兴趣的):

  1. 用鼠标选择文本,按下左键
  2. 使用中键粘贴文本

我升级了我的操作系统,这已经获得了一个新的tmux版本。我没有改变我的.tmux.conf配置文件。

这就是我当前版本的tmux1.6(它在最新的crunchbang linux中预先打包)所做的事情:

  1. 用鼠标,按下左键和Shift键选择文本
  2. 使用中键粘贴文本
  3. 终端被阻止,一个小小的信息区域显示当前窗格右上角的一些数字(即[0/24],可能与粘贴了多少个字符有关),这对我来说意义不大,我不需要/想要(编辑:似乎copy-mode在这里自动输入)
  4. 我必须按q键再次获得功能终端。

对于我每天做几十次的事情来说,这太麻烦了。如何让旧机制再次运作?

terminal gnu-screen tmux
9个回答
66
投票

要恢复默认的复制/粘贴配置,您需要(至少暂时)关闭tmux中的鼠标支持:

prefix : set -g mouse off

其中prefix是tmux访问键(默认情况下为Ctrl + B,除非您重新映射它)。 :启动命令模式,set -g全局设置参数。

关闭鼠标模式后,操作系统提供的标准复制/粘贴功能将按预期工作。

您可能想要做的其他事情是“最大化”当前窗格,这样您就可以轻松复制多行。


如果您正在使用旧版(2.1之前版本)的tmux,则需要使用以下内容:

prefix : set -g mode-mouse off

有更多的细节和一些方便的键绑定来自动化所有这些:

http://tangledhelix.com/blog/2012/07/16/tmux-and-mouse-mode/

上面链接的文章的主要内容是.tmux.conf的摘录:

# disable mouse control by default - change 'off' to 'on' to enable by default.
setw -g mode-mouse off
set-option -g mouse-resize-pane off
set-option -g mouse-select-pane off
set-option -g mouse-select-window off
# toggle mouse mode to allow mouse copy/paste
# set mouse on with prefix m
bind m \
    set -g mode-mouse on \;\
    set -g mouse-resize-pane on \;\
    set -g mouse-select-pane on \;\
    set -g mouse-select-window on \;\
    display 'Mouse: ON'
# set mouse off with prefix M
bind M \
    set -g mode-mouse off \;\
    set -g mouse-resize-pane off \;\
    set -g mouse-select-pane off \;\
    set -g mouse-select-window off \;\
    display 'Mouse: OFF'
# zoom this pane to full screen
bind + \
    new-window -d -n tmux-zoom 'clear && echo TMUX ZOOM && read' \;\
    swap-pane -s tmux-zoom.0 \;\
    select-window -t tmux-zoom
# restore this pane
bind - \
    last-window \;\
    swap-pane -s tmux-zoom.0 \;\
    kill-window -t tmux-zoom

207
投票
  1. 复制文本:选择文本并按left-button键同时按下鼠标shift
  2. 使用shift键+ middle-button粘贴文本

28
投票

如果“set -g mode-mouse on”你可以做到这一点:

在Mac上,按“fn”按钮,然后选择文本并用鼠标右键单击或键盘cmd + c复制。


6
投票

使用<prefix>+m打开或关闭鼠标模式

bind m run "if [[ `tmux show-option -w | grep mode-mouse.*on` ]]; then toggle=off; else toggle=on; fi; tmux display-message \"mouse tmux: \$toggle\"; tmux set-option -w mode-mouse \$toggle &> /dev/null; for cmd in mouse-select-pane mouse-resize-pane mouse-select-window; do tmux set-option -g \$cmd \$toggle &> /dev/null; done;"

6
投票

我有问题让Christian的例子为Tmux 2工作,我认为有些错别字。我得到了以下工作,并且更容易阅读并设置全局和窗口模式。某人新用户和tmux很棒!

bind m run "\
    tmux show-options -g | grep -q "mouse\\s*on"; \
    if [ \$? = 0 ]; \
    then  \
        toggle=off;  \
    else  \
        toggle=on;  \
    fi;  \
    tmux display-message \"mouse is now: \$toggle\";  \
    tmux set-option -w mouse \$toggle; \
    tmux set-option -g mouse \$toggle; \
    "

4
投票

修改自here - 我在原文中使用xclip而不是xsel

bind -T root MouseDown2Pane run -b "xclip -o | tmux load-buffer - && tmux paste-buffer -s ' '"

这对我在tmux 2.5-rc2欢快地工作


4
投票

对于Mac + iTerm2 + tmux(版本> 2.1)的用户:

确保在tmux config中设置了鼠标模式(只需在〜/ .tmux.conf中添加set -g mode-mouse on)。现在,要复制窗格内的文本:

  1. option + command并使用鼠标光标选择要复制的文本。这就像裁剪一张照片。
  2. 所选文本将自动复制(不需要command + c)。只需按常规方式粘贴即可。

2
投票

这是Kaixuan's answer的修改版本,与Tmux 2.1兼容。

`bind m run "if [[ `tmux show-options -w | grep mouse.*on` ]]; then toggle=off; else toggle=on; fi; tmux display-message \"mouse tmux: \$toggle\"; tmux set-option -w mouse \$toggle &> /dev/null;`"

所有mode-mouse选项已合并为一个mouse选项,show-option必须替换为show-options


0
投票

~/.tmux.conf

set -g mouse off

bind r source-file ~/.tmux.conf也可能有用,所以你可以做ctrl-d r重新加载配置。

© www.soinside.com 2019 - 2024. All rights reserved.