Vim 如何从putty中运行的tmux复制到windows剪贴板

Vim 如何从putty中运行的tmux复制到windows剪贴板,vim,tmux,Vim,Tmux,环境:我在putty中运行tmux,运行在Windows7笔记本电脑上。我在工作时使用ssh连接linux系统 在使用tmux满足所有需求之前,我必须解决tmux的两个问题 我必须从vim或tmux终端将一些文本复制到windows记事本。我已经为vim和putty启用了鼠标支持 我试过“*y和”+y,但两者都不起作用。如果我使用putty的复制功能,那么它也会复制相邻网格的内容 我必须将一个窗格中的vim文件中的一些内容复制到另一个窗格中打开的vim文件中。有没有什么vim技巧。我不想用[的

环境:我在putty中运行tmux,运行在Windows7笔记本电脑上。我在工作时使用ssh连接linux系统

在使用tmux满足所有需求之前,我必须解决tmux的两个问题

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

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

  • 我必须将一个窗格中的vim文件中的一些内容复制到另一个窗格中打开的vim文件中。有没有什么vim技巧。我不想用
    [
    的方式做这件事


  • 问题1更困扰着我,因为问题2有一个w/a。

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

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

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


    或者,如果您想继续使用PuTTY,您必须使用一些变通方法,例如
    :将所选内容写入本地文件,然后通过
    scp
    将其传输到Windows。我使用PuTTY v0.62和tmux v1.8

    tmux配置:setw-g模式鼠标打开

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


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

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

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

    基本成分:

    • 0.62(在Windows上)
    • 1.8(在一台Linux机器上)
    • (在Linux机器上)
    • (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

    " get some  autoselect interaction with the system clipboard
    set guioptions=aA
    
    我一直在运行此功能,但不必在xterm shell中运行tmux。请确保在X11设置中选择了共享剪贴板。我认为xming应该可以工作,但我的其他需要的设置似乎从来没有工作过。MobaXterm还有其他我喜欢的功能(文件浏览器等)

    我想我可以在MobaXterm中使用tmux运行ssh会话,但我更喜欢putty窗口,在该窗口中我有自己的应用程序

    腻子

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

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

    每个人都将共享剪贴板。当你拖动时,vim将复制到剪贴板。要粘贴到另一个tmux窗格中,请使用绑定键ctrl-p(我用ctrl-a ctrl-p)


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

    通过一些技巧,可以通过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' 
    
    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
    }
    
    2) 在服务器端
    .bashrc
    中,添加:

    # 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' 
    
    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\u打印机\u文件
    • 驱动程序>Microsoft XPS文档编写器
    • 打印机名称>“
      油灰打印机
    • 可选:打印测试页并确保它显示在文件@“
      %USERPROFILE%\Documents\PuTTY\u Printer\u file
      的内容中
    4) 在客户端PuTTY配置中:

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

    此时,您可以通过在tmux的复制模式下突出显示一些文本,然后按
    y
    ,将tmux缓冲区的内容发送到PuTTY客户端。所选文本将返回客户端上的
    %USERPROFILE%\Documents\PuTTY\u Printer\u文件
    。如果您想进一步模拟“粘贴”在此文件之外,您可以使用热键序列读取文件内容并将其插入。下面是一个利用自动热键的示例,但如果您愿意,也可以在PowerShell中实现相同的结果


    5) 客户端自动热键宏:

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