129

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

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

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

这就是我对当前版本的tmux, 1.6(在最新的 crunchbang linux 中预先打包)所做的事情:

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

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

4

13 回答 13

277
  1. 复制文本:选择文本并按下鼠标left-button按键shift
  2. shift用+ 键粘贴文本middle-button
于 2014-05-28T08:32:09.877 回答
95

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

prefix : set -g mouse off

prefixtmux 访问密钥在哪里(默认情况下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
于 2013-07-18T13:59:49.327 回答
41

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

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

于 2016-10-07T20:23:51.267 回答
24

tmux 2.6+

需要激活鼠标才能使其工作,所以这样做:Ctrl+B然后键入:set -g mouse on。(或者更好:在您的设置中设置此设置以tmux.conf保持一致性。)

视窗 10

激活鼠标模式后,在 Windows 上,您需要按Shift如下所述按下。

复制

  1. 按住Shift并用鼠标选择要复制的文本。
  2. 现在右键单击以复制选定的文本(不按住Shift)。

边缘案例:水平分割的窗格

当使用水平分割的窗格时,选择部分并不容易,因为多行的选择也会跨越多个窗格,选择您不想选择的文本部分。为了避免选择离开当前窗格Ctrl,同时按下Shift(感谢@Franck)。

另一种解决方法是快速更改窗格的布局(例如,使用Ctrl+B和然后Space),然后再将其更改回来。

粘贴

  1. 按住Shift并右键单击以插入复制的文本。

就那么简单。享受!

苹果系统

激活鼠标模式后,在 macOS 上,您需要按下fn。要复制选择,请照常使用CMD+ 。C

于 2019-10-11T11:43:02.990 回答
11

这里修改- 我使用xclip而不是xsel原来的:

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

这对我来说很愉快tmux 2.5-rc2

于 2017-05-13T16:04:19.943 回答
9

使用<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;"
于 2015-07-15T04:44:40.627 回答
6

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

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

  1. 按下option + command并使用鼠标光标选择要复制的文本。这就像裁剪图片一样。
  2. 所选文本将自动复制(不需要command + c)。只需按常规方式粘贴即可。
于 2018-10-27T00:58:41.933 回答
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; \
    "
于 2016-04-22T15:00:00.423 回答
3

这是与 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

于 2016-01-20T19:04:51.910 回答
0

~/.tmux.conf

set -g mouse off

bind r source-file ~/.tmux.conf可能也很有用,因此您可以重新ctrl-d r加载配置。

于 2019-05-11T16:11:50.887 回答
0

这是鼠标切换的更新版本,在 tmux v3.1 上测试

由于代码是单行代码,为了保持简短,我只使用 t 作为变量名,并将 if 语句替换为查找字母 n 的条件语句。条件允许我们从中删除很多空格和分号,从而进一步缩短行。

bind m run "[[ `tmux show -gv mou` = *n* ]]&&t=off||t=on;tmux set -g mou \$t;tmux display-message \"mouse mode: \$t\""

这是扩展为更具可读性的代码片段

[[ `tmux show -gv mouse` = *n* ]] && t=off || t=on
tmux set -g mouse $t
tmux display-message "mouse mode: $t"
于 2020-08-18T22:52:00.650 回答
0

根据此处发布的其他答案,我创建了一个简洁的解决方案,该解决方案(至少)适用于 tmux 2.8tmux 3.1

您可以tmux mouse support通过按prefix-来打开和关闭M。在.tmux.conf文件中,包含以下行:

bind-key -T prefix m run "m=$(tmux show -g mou|grep -q on;echo $?);tmux set -g mou $m;tmux display mouse:\$m"

这将mouse: 1在启用和mouse: 0禁用时显示。反复按prefix-将在打开关闭M之间切换鼠标模式。

另请参阅:tmux 鼠标支持

编辑:如果您看到命令returned 1错误消息,则需要将以下内容用于tmux 3.1tmux 3.2

bind-key -T prefix m set -g mouse\; display 'Mouse: #{?mouse,ON,OFF}'

(这个解决方案之前提到过)

于 2020-06-01T12:40:24.313 回答
-1

我使用以下绑定来选择按下鼠标左键的文本 -

bind -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "/mnt/c/Windows/System32/clip.exe"
于 2020-06-29T20:53:45.840 回答