我正在使用tmux和OSX。当使用tmux从终端复制和粘贴时,我能够按住Option并选择文本。但是,我不能让文本留在窗格中。因此,当我想要复制文本时,我需要将窗格循环到最左边,或者缩放窗格,如下所示。
除了必须按住Option键之外,这也是一种痛苦。我知道我可以进入视觉模式并使用vim动作来达到目的,但我更希望有一种方法使用我的鼠标。有人找到解决办法了吗?


发布于 2016-10-23 09:24:05
将这段代码放入您的~/.tmux.conf中。这将启用鼠标集成,允许您使用鼠标从窗格中复制,而不必缩放。
set -g mouse on
bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'select-pane -t=; copy-mode -e; send-keys -M'"
bind -n WheelDownPane select-pane -t= \; send-keys -M
bind -n C-WheelUpPane select-pane -t= \; copy-mode -e \; send-keys -M
bind -t vi-copy C-WheelUpPane halfpage-up
bind -t vi-copy C-WheelDownPane halfpage-down
bind -t emacs-copy C-WheelUpPane halfpage-up
bind -t emacs-copy C-WheelDownPane halfpage-down
# To copy, drag to highlight text in yellow, press Enter and then release mouse
# Use vim keybindings in copy mode
setw -g mode-keys vi
# Update default binding of `Enter` to also use copy-pipe
unbind -t vi-copy Enter
bind-key -t vi-copy Enter copy-pipe "pbcopy"之后,重新启动tmux会话。用鼠标高亮显示一些文本,但不要松开鼠标。现在,当文本仍然高亮显示并按下鼠标时,请按返回键。突出显示的文本将消失,并将复制到您的剪贴板。现在释放鼠标。
除此之外,还有一些你可以用鼠标做的很酷的事情,比如上下滚动,选择活动窗格等等。
如果您在macOS上使用较新版本的tmux,请尝试以下方法,而不是上面的版本:
# macOS only
set -g mouse on
bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'select-pane -t=; copy-mode -e; send-keys -M'"
bind -n WheelDownPane select-pane -t= \; send-keys -M
bind -n C-WheelUpPane select-pane -t= \; copy-mode -e \; send-keys -M
bind -T copy-mode-vi C-WheelUpPane send-keys -X halfpage-up
bind -T copy-mode-vi C-WheelDownPane send-keys -X halfpage-down
bind -T copy-mode-emacs C-WheelUpPane send-keys -X halfpage-up
bind -T copy-mode-emacs C-WheelDownPane send-keys -X halfpage-down
# To copy, left click and drag to highlight text in yellow,
# once you release left click yellow text will disappear and will automatically be available in clibboard
# # Use vim keybindings in copy mode
setw -g mode-keys vi
# Update default binding of `Enter` to also use copy-pipe
unbind -T copy-mode-vi Enter
bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "pbcopy"
bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "pbcopy"如果在iTerm上使用macOS,goto iTerm2 > Preferences >“General”选项卡,在“选择”部分,检查“终端中的应用程序可以访问剪贴板”。
如果您正在使用Linux和较新版本的tmux,那么
# Linux only
set -g mouse on
bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'select-pane -t=; copy-mode -e; send-keys -M'"
bind -n WheelDownPane select-pane -t= \; send-keys -M
bind -n C-WheelUpPane select-pane -t= \; copy-mode -e \; send-keys -M
bind -T copy-mode-vi C-WheelUpPane send-keys -X halfpage-up
bind -T copy-mode-vi C-WheelDownPane send-keys -X halfpage-down
bind -T copy-mode-emacs C-WheelUpPane send-keys -X halfpage-up
bind -T copy-mode-emacs C-WheelDownPane send-keys -X halfpage-down
# To copy, left click and drag to highlight text in yellow,
# once you release left click yellow text will disappear and will automatically be available in clibboard
# # Use vim keybindings in copy mode
setw -g mode-keys vi
# Update default binding of `Enter` to also use copy-pipe
unbind -T copy-mode-vi Enter
bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "xclip -selection c"
bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "xclip -in -selection clipboard"在基于Debian和Debian的发行版(Ubuntu,Kali)中,您可能需要安装xclip:
sudo apt-get install -y xclip(您还可以查看https://github.com/gpakosz/.tmux中的许多其他tmux选项。)
发布于 2021-09-16 04:15:28
在~/.tmux.conf中添加这2行
set -g @plugin 'tmux-plugins/tmux-yank'
set -g mouse on然后为我安装插件。
发布于 2021-02-18 19:59:18
tmux有自己的内部剪贴板,不复制到系统剪贴板。
但是,由于您在macOS上,您可以简单地要求tmux将其剪贴板传输到系统剪贴板(通常的剪贴板)。这是通过下面的命令来完成的,为了方便起见,它可以绑定到.tmux.conf中的Ctrl(如果您使用标准Ctrl来调用tmux命令):
bind C-c run "tmux save-buffer - | pbcopy" # Copy to macOS因此,您可以使用tmux (没有按下键)使用鼠标选择文本。tmux很棒,因为它将只在当前窗格中选择文本(即使您同时拥有多个窗格)。此文本被复制到tmux的内部剪贴板上。然后,您可以使用Ctrl将其简单地传输到系统剪贴板上。
https://unix.stackexchange.com/questions/318281
复制相似问题