简体   繁体   English

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

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

Now for copy to system clipboard I have to select via mouse text in tmux window with Shift key.现在要复制到系统剪贴板,我必须使用Shift键在 tmux 窗口中通过鼠标文本进行选择。 And then I have to run this command:然后我必须运行这个命令:

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

Is any chance to save to system clipboard easier?有没有机会更容易地保存到系统剪贴板? Key bind or better do that automatically after Shift release.键绑定或更好地在 Shift 释放后自动执行此操作。

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

If you are using iTerm2, you can copy text in Tmux session, holding down the Option key while dragging the mouse to make selection.如果您使用的是 iTerm2,您可以在 Tmux 会话中复制文本,按住Option键的同时拖动鼠标进行选择。

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

If you use iTerm2 3.x, you can make copy / paste work by enabling Applications in terminal may access clipboard :如果您使用 iTerm2 3.x,您可以通过Applications in terminal may access clipboard启用Applications in terminal may access clipboard来进行复制/粘贴工作:

在此处输入图片说明

Just highlight text with your mouse to copy it into the macOS clipboard!只需用鼠标突出显示文本即可将其复制到 macOS 剪贴板中! No need to press Option as suggested in the accepter answer.无需按接受者答案中的建议按选项

You can also paste from the macOS clipboard into tmux with the usual Cmd + V .您还可以使用通常的Cmd + V将 macOS 剪贴板粘贴到 tmux 中。

For os x, If you use app "Terminal".对于 os x,如果您使用应用程序“终端”。 You can switch off mouse scroll and use usual copy/paste functions (cmd+c/cmd+v):您可以关闭鼠标滚动并使用通常的复制/粘贴功能(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

or you can use mouse scroll and select text using "fn key":或者您可以使用鼠标滚动并使用“fn 键”选择文本:

set-window-option -g mode-mouse on

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

Solution found there:在那里找到的解决方案:

# 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"

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

if you have set the following options:如果您设置了以下选项:

mouse-select-pane鼠标选择面板

mouse-select-window鼠标选择窗口

you will notice that you are not able to select text at all.您会注意到您根本无法选择文本。

the solution is to use the shift key.解决方法是使用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.

On OSX using tmux version 2.2 or later add the following to your tmux.conf file:在使用 tmux 2.2 或更高版本的 OSX 上,将以下内容添加到 tmux.conf 文件中:

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

For tmux version 2.4, since they kindly decided to change the command syntax, you should use:对于 tmux 2.4 版,由于他们好心地决定更改命令语法,您应该使用:

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

Note that you may also need to use reattach-to-user-namespace pbcopy instead of plain pbcopy .请注意,您可能还需要使用reattach-to-user-namespace pbcopy而不是普通的pbcopy

Putting this in my ~/.tmux.conf file works for me:把它放在我的 ~/.tmux.conf 文件中对我有用:

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

All other potential solutions I found were copying some sort of empty content to the OSX clipboard.我发现的所有其他潜在解决方案都是将某种空内容复制到 OSX 剪贴板。

The only problem is that this seems to put a carriage return at the end of the pasted content.唯一的问题是,这似乎在粘贴内容的末尾放了一个回车。

press the left mouse button and hold it, select text in pane and still hold the button down.按住鼠标左键,在窗格中选择文本并按住按钮。 then press "y", which saves selection within clipboard and escapes from selection/copy mode.然后按“y”,这会将选择保存在剪贴板中并退出选择/复制模式。

works here with iTerm 3.1.beta.5, tmux 2.5 and the following config:在这里使用 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"

press shift key and then mouse click!!按shift键然后鼠标点击!! Check this link.检查此链接。 http://awhan.wordpress.com/2012/04/18/tmux-copy-paste-with-mouse/ 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解决此问题。

Here's the solution I'm using for tmux version 2.8, macOS Mojave 10.14.1, and Terminal.app.这是我用于tmux 2.8、macOS Mojave 10.14.1 和 Terminal.app 的解决方案。

After releasing the mouse button, this removes the selection while copying to the system clipboard (as well as the tmux buffer):释放鼠标按钮后,这会在复制到系统剪贴板(以及tmux缓冲区)时删除选择:

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

I made a version using netcat today that is pretty dead simple.我今天使用 netcat 制作了一个非常简单的版本。

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

Here is the tmux.conf:这是 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

Works with the mouse too in 1.8在 1.8 中也适用于鼠标

A robust solution that works with any combination of mosh + tmux + vim + nested sessions一个强大的解决方案,适用于 mosh + tmux + vim + 嵌套会话的任意组合

After spending many days tackling this, by far the most robust solution I've discovered is Suraj N. Kurapati's posted solution .在花了很多天解决这个问题之后,到目前为止我发现的最强大的解决方案是 Suraj N. Kurapati发布的解决方案 The solution works locally with (and without) tmux v3.2 and/or vim, as well as remotely with (and without) tmux and/or vim , using both copy-mode keys and simple mouse selection.该解决方案使用(和不使用) tmux v3.2 和/或 vim 在本地工作,以及使用(和不使用) tmux和/或vim远程工作,使用复制模式键和简单的鼠标选择。

If combined with Mike Gulick's (currently open) pull request , all of these combinations work with mosh as well.如果与 Mike Gulick 的(当前开放的) pull request结合使用,所有这些组合也适用于mosh

Until Mike's solution is merged into mosh, you can pull his changes and build locally using:在 Mike 的解决方案合并到 mosh 之前,您可以使用以下方法提取他的更改并在本地构建:

Ubuntu: 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

macOS:苹果系统:

I think you need to install Apple's Xcode/Developer Command Line Tools first (which, IIRC, can now be done by simply running gcc and exiting), then running:我认为您需要先安装 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

With these updates, the clipboard holy grail has finally been achieved!通过这些更新,剪贴板的圣杯终于实现了!

However, this is very new information, thus this post of mine is rather volatile.然而,这是非常新的信息,因此我的这篇文章相当不稳定。 Therefore:所以:

Please kindly revise my post if:如果出现以下情况,请修改我的帖子:

  1. I'm missing dependencies, etc, or我缺少依赖项等,或者
  2. Performing a gh pr checkout 1104 of Mike's changes is no longer needed because it's been merged into mosh, or不再需要对 Mike 的更改执行gh pr checkout 1104 ,因为它已合并到 mosh,或
  3. Building from source is no longer needed because the merged changes have been pushed to brew/apt/etc package managers.不再需要从源代码构建,因为合并的更改已推送到 brew/apt/etc 包管理器。

On macOS Terminal Tmux, copying from a specific pane:在 macOS 终端 Tmux 上,从特定窗格复制:

  1. Hold option (cursor changes to crosshair) [See * below]保持选项(光标更改为十字准线)[见下面的 *]
  2. Click and drag to select text单击并拖动以选择文本
  3. Copy/paste as normal, with CMD-C/V正常复制/粘贴,使用 CMD-C/V

*You may need to toggle "Allow mouse reporting" with CMD-R (see Terminal, View-...). *您可能需要使用 CMD-R 切换“允许鼠标报告”(请参阅​​终端,查看-...)。 I find that I often toggle this to either scroll with mouse inside tmux panes, or to copy-paste.我发现我经常将其切换为在 tmux 窗格内用鼠标滚动或复制粘贴。


In my .tmux.conf , I include set -g mouse on在我的.tmux.conf ,我包括set -g mouse on

This is on macOS Catalina, tmux 3.1c这是在 macOS Catalina 上,tmux 3.1c

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

monterey macosx terminal 2.21 with default settings connected to a machine over ssh with tmux 2.6 running on it, with several panes, tmux config there is as simple as that: monterey macosx 终端 2.21 的默认设置通过 ssh 连接到一台机器,上面运行着 tmux 2.6,有几个窗格,tmux 配置就这么简单:

set -g mouse on

To copy - hold the 🌐 Fn button and select what you need using mouse, then press ⌘ Command + C , et voila, the text is in the buffer on your mac.要复制 - 按住🌐 Fn按钮并使用鼠标选择您需要的内容,然后按⌘ Command + C ,等等,文本在您的 mac 缓冲区中。

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

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