31

ENV:我在 Windows 7 笔记本电脑上的 putty 中运行 tmux。我在工作时对 linux 系统进行 ssh。

我必须先用 tmux 解决两个故障,然后再使用它来满足我的所有需求。

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

    我已经尝试过"*y"+y但它们都不起作用。如果我使用腻子的复制能力,那么它也会复制相邻网格的内容。

  2. 我必须将一些内容从一个窗格中的 vim 文件复制到另一个窗格中打开的 vim 文件。是否有任何 vim 技巧。我不想使用<C-b>[这样做的方式。

问题 1 更困扰我,因为问题 2 有 aw/a。

4

5 回答 5

123

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

tmux 配置:setw -g mode-mouse on

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

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

于 2013-11-15T08:17:07.770 回答
15

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

我确实在 Windows 上运行了 X 服务器(不需要在 Windows 上,但你需要一个)。

基本成分:

  • 腻子0.62(在 Windows 上)
  • tmux 1.8(在一台 Linux 机器上)
  • xclip(在 Linux 机器上)
  • MobaXterm(在 Windows 上用于他们的 x 服务器)

您的网络设置可能会有所不同,尤其是在 X 服务器显示配置上,但这里是:

多路复用器

# 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 会话,但我更喜欢 putty 窗口,其中有我的太阳能调色板

油灰

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

在任何将共享剪贴板的机器上,确保您有正确的$DISPLAY设置。您应该能够xeyes在本地计算机上运行并查看它。

每个人都将共享剪贴板。vim 会在你 yank 时复制到剪贴板。要粘贴到另一个 tmux 窗格中,请使用绑定键 ctrl-p(对我来说是 ctrl-a ctrl-p)。

如果它不起作用,您可以随时尝试xclip -o -selection clipboard查看应该粘贴的内容。您还可以使用(即 tmux yank)将任何“tmux selected”文本(鼠标或bind-key [)移动到剪贴板(从而移动到常规 Windows 窗口)。bind-key ctrl-y

于 2013-12-27T17:25:47.513 回答
5

PuTTY 只是一个终端仿真器;Vim 注册*+关注 X 选择和剪贴板;没有重叠。

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

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

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

于 2013-06-23T19:50:01.717 回答
4

通过一些技巧,可以通过 PuTTY 将 tmux 缓冲区返回到客户端。我使用“AUX”端口(串行打印机)的 ANSI 转义码完成了这项工作。

这只是该传输方法的一种实现:

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) 上,创建新打印机:

  • 添加打印机
  • 创建一个新端口 > 本地端口
  • 输入端口名称 > " PuTTY_Printer_File"
  • 驱动程序 > Microsoft XPS 文档编写器
  • 打印机名称 > " PuTTY Printer"
  • 可选:打印测试页并确保它显示在文件@“ %USERPROFILE%\Documents\PuTTY_Printer_File”的内容中

4) 在客户端 PuTTY 配置中:

  • 设置终端>“打印机将ANSI打印机输出发送到:”到新创建的名为“ PuTTY Printer”的打印机
  • 将 Connection > SSH > "Remote command:" 设置为 " t"(参考上面的 .bashrc 函数)

此时,您可以通过突出显示 tmux 的复制模式中的一些文本,然后按 将 tmux 缓冲区的内容发送到 PuTTY 客户端y。选定的文本将最终%USERPROFILE%\Documents\PuTTY_Printer_File返回客户端。如果您想更进一步并从该文件中模拟“粘贴”,您可以使用热键序列来读取文件的内容并将其插入。这是一个利用 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将粘贴选择

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

于 2017-01-10T04:03:49.117 回答
1

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

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

在 v2.6 上测试

于 2018-08-09T03:58:06.297 回答