如何从在putty中运行的tmux复制到Windows剪贴板

时间:2013-06-22 20:31:39

标签: vim tmux

ENV:我在putty上运行tmux,在Windows 7笔记本电脑上运行。我在工作时使用ssh到linux系统。

我必须用tmux解决两个故障,然后才能满足我的所有需求。

  1. 我必须从vim或tmux终端将一些文本复制到Windows记事本中。我已经为vim和putty启用了鼠标支持。

    我尝试了"*y"+y,但两者都不起作用。如果我使用putty的复制能力,那么它也会复制相邻网格的内容。

  2. 我必须将一个窗格中的某些内容从一个窗格中的vim文件复制到另一个窗格中打开的vim文件。这有什么vim技巧吗?我不想使用<C-b>[方式来做这件事。

  3. 问题1更多地困扰着我,因为问题2有一个w / a。

5 个答案:

答案 0 :(得分:91)

我使用putty v0.62和tmux v1.8。

tmux config:setw -g mode-mouse on

我想将一些文本从tmux复制到系统剪贴板,我按住SHIFT并用鼠标选择文本,然后单击鼠标左键。

我想将一些文本粘贴到tmux中,按SHIFT并单击鼠标右键。

答案 1 :(得分:15)

这绝对是可能的。下面的所有配置行都是从不同tmux窗格中的计算机复制回我的Windows计算机。是的,我把putty放到一台机器上,tmux和ssh从那里到其他人,可以将我的vim移动到任何机器,包括我的Windows浏览器。

我在Windows上运行X服务器(不需要在Windows上,但你需要在某个地方)。

基本成分:

  • putty 0.62(在Windows上)
  • tmux 1.8(在一台Linux机器上)
  • xclip(在Linux机器上)
  • MobaXterm(在Windows上为其x服务器)

您的网络设置可能略有不同,尤其是在X服务器显示配置上,但在此处:

tmux

# allow mouse to select panes
setw -g mode-mouse on
set-option -g mouse-select-pane on

# allow yank into system clipboard
#bind C-y run "tmux save-buffer - | xclip -i"
bind C-y run-shell -b "tmux show-buffer | xclip -selection clipboard -i"
# move x clipboard into tmux paste buffer
bind C-p run-shell -b "xclip -o -selection clipboard | tmux load-buffer - ; tmux paste-buffer"

<强> VIM

" get some  autoselect interaction with the system clipboard
set guioptions=aA

<强> MobaXterm

我保持运行,但不必在xterm shell中运行tmux。确保在X11设置中选择了共享剪贴板。我想xming应该可以工作,但我的其他需求的设置似乎永远不会成功。 MobaXterm还有其他我喜欢的好东西(文件浏览器等)。

我想我可以在MobaXterm中使用tmux运行ssh会话,但我更喜欢我拥有solarized color palette的putty窗口。

<强>腻子

使用tmux ssh到机器。此时,我设置了DISPLAY环境变量并将其放在由bash提供的env文件中。这样,创建的每个后续窗口都将设置它。在我从tmux机器上跳到的其他机器上设置它完全是一个单独的练习。

在要共享剪贴板的任何计算机中,请确保您拥有正确的$DISPLAY集。您应该能够运行xeyes并在本地计算机上查看它。

每个人都将共享剪贴板。当你猛拉时,vim会复制到剪贴板。要粘贴到另一个tmux窗格,请使用bind-key ctrl -p(ctrl-a ctrl -p for me)。

如果它不起作用,您可以随时尝试xclip -o -selection clipboard查看应粘贴的内容。你也可以移动选择的任何&#34; tmux&#34;使用bind-key [(即tmux yank)将文本(鼠标或bind-key ctrl-y)添加到剪贴板(以及常规窗口窗口)。

答案 2 :(得分:6)

PuTTY只是一个终端模拟器; Vim寄存器*+关注X选择和剪贴板;没有重叠。

PuTTY只允许您将选定的终端内容复制到Windows剪贴板;当你运行 tmux 时,这将不可避免地包括窗口布局。

你需要从Pu​​TTY切换到允许真正集成的东西,比如 Cygwin XWin服务器,这是一个真正的X服务器,它将X剪贴板与Windows剪贴板集成在一起。您可以ssh -X进入您的服务器,而不是在PuTTY会话中,直接在Linux终端或GVIM中启动Vim。然后,通过"+y进行操作将按预期工作。

或者,如果您想继续使用PuTTY,则必须使用一些解决方法,例如{{1}选择本地文件,然后通过:write将其传输到Windows

答案 3 :(得分:4)

通过一些技巧,可以通过PuTTY将tmux缓冲区恢复到客户端。我使用ANSI转义码完成了这个&#34; AUX&#34;端口(串行打印机)。

这只是转移方法的一个实现:

1)在服务器端tmux.conf中,添加:

# Send the tmux copy buffer to a file.  The file is read for ANSI printing by "t" alias in .bashrc
bind -t vi-copy y copy-pipe 'cat > ~/.tmux-buffer' 

2)在服务器端.bashrc中,添加:

t() {
  # Configure a PuTTY profile to send "t" as the "Remote command".  This
  # function will automatically reattach to an existing tmux session if one
  # exists, or start a new one.  This function also repeatedly sends our
  # homemade tmux clipboard back to the PuTTY client in the form of an ANSI
  # printer escape sequence.  The contents of the homemade clipboard are
  # populated by `bind -t vi-copy y copy-pipe 'cat > ~/.tmux-buffer'` in
  # tmux.conf.  It is expected that the PuTTY client will be configured to
  # print to a "Microsoft XPS Document Writer" which saves the printer output
  # to a file.  The file is subsequently read by an AutoHotkey macro, and the
  # contents are made available for paste.
  [[ "$TERM" == "xterm" ]] || return 0 # This prevents recursive runs, in case t() is called after tmux is started.
  { while :; do tput mc5; cat ~/.tmux-buffer; tput mc4; sleep 5; done } &
  tmux attach || tmux
}

3)在客户端(Microsoft Windows),创建新打印机:

  • 添加打印机
  • 创建新端口&gt;本地港口
  • 输入端口名称&gt; &#34; PuTTY_Printer_File&#34;
  • 驱动程序&gt; Microsoft XPS Document Writer
  • 打印机名称&gt; &#34; PuTTY Printer&#34;
  • 可选:打印测试页并确保其显示在文件@&#34; %USERPROFILE%\Documents\PuTTY_Printer_File&#34;
  • 的内容中

4)在客户端PuTTY配置中:

  • 设置终端&gt; &#34;打印机将ANSI打印机输出发送到:&#34;到新创建的名为&#34; PuTTY Printer&#34;
  • 的打印机
  • 设置连接&gt; SSH&gt; &#34;远程命令:&#34;到&#34; t&#34; (引用上面的.bashrc函数)

此时,您可以通过突出显示tmux复制模式中的某些文本,然后按y,将tmux缓冲区的内容发送到PuTTY客户端。所选文本将以%USERPROFILE%\Documents\PuTTY_Printer_File结尾返回客户端。如果你想更进一步,模仿&#34;粘贴&#34;在此文件之外,您可以使用热键序列来读取文件的内容并将其插入。这是一个利用AutoHotKey的示例,但如果您愿意,可能会在PowerShell中实现相同的结果。

5)客户端AutoHotKey宏:

;### Get contents of PuTTY ANSI printer device output and paste it
#v:: ;Winkey + v
FileRead, PuTTYPrinter, %USERPROFILE%\Documents\PuTTY_Printer_File
SendInput %PuTTYPrinter%
PuTTYPrinter = ; Free up memory
return

6)完整的使用程序:

  • 使用PuTTY连接到服务器,并通过t()函数进入tmux。
  • 准备选择要复制的文本时,请使用tmux热键进行复制模式(Ctrl + b[
  • 使用箭头键移动光标
  • 使用spacebar
  • 开始选择
  • 结束选择并使用y
  • 进行复制
  • 回到客户端运行的PuTTY,WindowsKey + v将粘贴选择

由于图片价值1000字,以下是对正在发生的事情的概述: https://media.licdn.com/mpr/mpr/AAEAAQAAAAAAAAfiAAAAJDYzM2RmMzYzLTk1NmQtNGQxMi1iN2YyLTQ4NGUxNjExMmVlOA.png

答案 4 :(得分:1)

假设鼠标模式已打开,请将其添加到tmux配置中,然后选择将复制到剪贴板。

bind -Tcopy-mode MouseDragEnd1Pane send -X copy-selection-and-cancel\; run-shell -b "tmux show-buffer | clip"

在v2.6上测试