繁体   English   中英

鼠标选择后如何从tmux输出复制到系统剪贴板?

[英]How to copy to system clipboard from tmux output after mouse selection?

现在要复制到系统剪贴板,我必须使用Shift键在 tmux 窗口中通过鼠标文本进行选择。 然后我必须运行这个命令:

tmux save-buffer - | reattach-to-user-namespace pbcopy

有没有机会更容易地保存到系统剪贴板? 键绑定或更好地在 Shift 释放后自动执行此操作。

我的 tmux 配置: https : //gist.github.com/3641580

如果您使用的是 iTerm2,您可以在 Tmux 会话中复制文本,按住Option键的同时拖动鼠标进行选择。

然后应该可以像往常一样使用Cmd + V将文本粘贴到任何地方。 在这里找到: http : //web.archive.org/web/20131226003700/http : //ootput.wordpress.com/2013/08/02/copy-and-paste-in-tmux-with-mouse/

如果您使用 iTerm2 3.x,您可以通过Applications in terminal may access clipboard启用Applications in terminal may access clipboard来进行复制/粘贴工作:

在此处输入图片说明

只需用鼠标突出显示文本即可将其复制到 macOS 剪贴板中! 无需按接受者答案中的建议按选项

您还可以使用通常的Cmd + V将 macOS 剪贴板粘贴到 tmux 中。

对于 os x,如果您使用应用程序“终端”。 您可以关闭鼠标滚动并使用通常的复制/粘贴功能(cmd+c/cmd+v):

set-option -g mouse-select-pane off
set-option -g mouse-resize-pane off
set-option -g mouse-select-window off
set-window-option -g mode-mouse off

或者您可以使用鼠标滚动并使用“fn 键”选择文本:

set-window-option -g mode-mouse on

这里回答了一个类似的问题: https : //unix.stackexchange.com/questions/15715/getting-tmux-to-copy-a-buffer-to-the-clipboard

在那里找到的解决方案:

# move x clipboard into tmux paste buffer
bind C-p run "tmux set-buffer \"$(xclip -o)\"; tmux paste-buffer"
# move tmux copy buffer into x clipboard
bind C-y run "tmux show-buffer | xclip -i"

另请检查: http : //awhan.wordpress.com/2012/04/18/tmux-copy-paste-with-mouse/

如果您设置了以下选项:

鼠标选择面板

鼠标选择窗口

您会注意到您根本无法选择文本。

解决方法是使用shift键。

hold down the shift key and then left click and drag across the target text. you must also hold down the shift key and then middle click in order to paste the text.

在使用 tmux 2.2 或更高版本的 OSX 上,将以下内容添加到 tmux.conf 文件中:

bind-key -t emacs-copy MouseDragEnd1Pane copy-pipe "pbcopy"
bind-key -t vi-copy MouseDragEnd1Pane copy-pipe "pbcopy"

对于 tmux 2.4 版,由于他们好心地决定更改命令语法,您应该使用:

bind-key -T copy-mode MouseDragEnd1Pane send -X copy-pipe-and-cancel "pbcopy"

请注意,您可能还需要使用reattach-to-user-namespace pbcopy而不是普通的pbcopy

把它放在我的 ~/.tmux.conf 文件中对我有用:

bind y run-shell "reattach-to-user-namespace -l zsh -c 'tmux show-buffer | pbcopy'"

我发现的所有其他潜在解决方案都是将某种空内容复制到 OSX 剪贴板。

唯一的问题是,这似乎在粘贴内容的末尾放了一个回车。

按住鼠标左键,在窗格中选择文本并按住按钮。 然后按“y”,这会将选择保存在剪贴板中并退出选择/复制模式。

在这里使用 iTerm 3.1.beta.5、tmux 2.5 和以下配置:

### copy & paste -------------------------------------------------------
# Use vim keybindings in copy mode
setw -g mode-keys vi
# Setup 'v' to begin selection as in Vim
bind-key -T copy-mode-vi v send -X begin-selection
bind-key -T copy-mode-vi y send -X copy-pipe-and-cancel "reattach-to-user-namespace pbcopy"
# Update default binding of `Enter` to also use copy-pipe
unbind -T copy-mode-vi Enter
bind-key -T copy-mode-vi Enter send -X copy-pipe-and-cancel "reattach-to-user-namespace pbcopy"

按shift键然后鼠标点击!! 检查此链接。 http://awhan.wordpress.com/2012/04/18/tmux-copy-paste-with-mouse/

在 macOS High Sierra 的Terminal应用程序中,使用FN + mouse drag with left button downtmux窗口选择文本后,我能够使用CMD + C解决此问题。

这是我用于tmux 2.8、macOS Mojave 10.14.1 和 Terminal.app 的解决方案。

释放鼠标按钮后,这会在复制到系统剪贴板(以及tmux缓冲区)时删除选择:

bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "pbcopy"

我今天使用 netcat 制作了一个非常简单的版本。

https://github.com/base698/tmux-copy-paste-mac-osx

这是 tmux.conf:

bind -t vi-copy 'v' begin-selection
bind -t vi-copy 'y' copy-pipe 'nc localhost 5682'
bind p run-shell 'nc localhost 5683; nc localhost 5683 | tmux load-buffer -' \; paste-buffer

在 1.8 中也适用于鼠标

一个强大的解决方案,适用于 mosh + tmux + vim + 嵌套会话的任意组合

在花了很多天解决这个问题之后,到目前为止我发现的最强大的解决方案是 Suraj N. Kurapati发布的解决方案 该解决方案使用(和不使用) tmux v3.2 和/或 vim 在本地工作,以及使用(和不使用) tmux和/或vim远程工作,使用复制模式键和简单的鼠标选择。

如果与 Mike Gulick 的(当前开放的) pull request结合使用,所有这些组合也适用于mosh

在 Mike 的解决方案合并到 mosh 之前,您可以使用以下方法提取他的更改并在本地构建:

Ubuntu:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key C99B11DEB97541F0 \
&& sudo apt-add-repository https://cli.github.com/packages \
&& sudo apt update \
&& sudo apt install -y gh autoconf automake perl protobuf-compiler libprotobuf-dev libncurses-dev zlib1g-dev libutempter-dev libssl-dev pkg-config \
&& mkdir -p ~/tmp/mosh \
&& git clone https://github.com/mobile-shell/mosh ~/tmp/mosh \
&& cd ~/tmp/mosh \
&& gh pr checkout 1104 \
&& ./autogen.sh \
&& ./configure \
&& make \
&& sudo make install

苹果系统:

我认为您需要先安装 Apple 的 Xcode/Developer Command Line Tools(IIRC 现在只需运行gcc并退出即可完成),然后运行:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" \
&& brew install gh autoconf automake
&& mkdir -p ~/tmp/mosh \
&& git clone https://github.com/mobile-shell/mosh ~/tmp/mosh \
&& cd ~/tmp/mosh \
&& gh pr checkout 1104 \
&& ./autogen.sh \
&& ./configure \
&& make \
&& sudo make install

通过这些更新,剪贴板的圣杯终于实现了!

然而,这是非常新的信息,因此我的这篇文章相当不稳定。 所以:

如果出现以下情况,请修改我的帖子:

  1. 我缺少依赖项等,或者
  2. 不再需要对 Mike 的更改执行gh pr checkout 1104 ,因为它已合并到 mosh,或
  3. 不再需要从源代码构建,因为合并的更改已推送到 brew/apt/etc 包管理器。

在 macOS 终端 Tmux 上,从特定窗格复制:

  1. 保持选项(光标更改为十字准线)[见下面的 *]
  2. 单击并拖动以选择文本
  3. 正常复制/粘贴,使用 CMD-C/V

*您可能需要使用 CMD-R 切换“允许鼠标报告”(请参阅​​终端,查看-...)。 我发现我经常将其切换为在 tmux 窗格内用鼠标滚动或复制粘贴。


在我的.tmux.conf ,我包括set -g mouse on

这是在 macOS Catalina 上,tmux 3.1c

对于那些现在在 mac 中寻找 tmux 中选择如何工作的人:使用“fn”键来选择、复制和粘贴。

monterey macosx 终端 2.21 的默认设置通过 ssh 连接到一台机器,上面运行着 tmux 2.6,有几个窗格,tmux 配置就这么简单:

set -g mouse on

要复制 - 按住🌐 Fn按钮并使用鼠标选择您需要的内容,然后按⌘ Command + C ,等等,文本在您的 mac 缓冲区中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM