System Clipboard Vim within TMUX within SSH session

前端 未结 3 1758
时光取名叫无心
时光取名叫无心 2021-01-18 16:16

I have vim open inside tmux inside an ssh session. How can I make vim use my laptop\'s system clipboard as the default copy paste? The default set clipboard=unamed

相关标签:
3条回答
  • 2021-01-18 16:35

    Clipboard integration feature (PASTE64/OSC52) is helpful if your terminal emulator supports it. For example, iTerm2 supports it (I am not sure about Ubuntu).

    Add this function to your "remote" .vimrc. yank something and run :OscCopy. It works even it is inside tmux session.

    function! OscCopy()
      let encodedText=@"
      let encodedText=substitute(encodedText, '\', '\\\\', "g")
      let encodedText=substitute(encodedText, "'", "'\\\\''", "g")
      let executeCmd="echo -n '".encodedText."' | base64 | tr -d '\\n'"
      let encodedText=system(executeCmd)
      if $TMUX != ""
        "tmux
        let executeCmd='echo -en "\x1bPtmux;\x1b\x1b]52;;'.encodedText.'\x1b\x1b\\\\\x1b\\" > /dev/tty'
      else
        let executeCmd='echo -en "\x1b]52;;'.encodedText.'\x1b\\" > /dev/tty'
      endif
      call system(executeCmd)
      redraw!
    endfunction
    command! OscCopy :call OscCopy()
    

    gist

    0 讨论(0)
  • 2021-01-18 16:51

    For the osc52 copy, there's plugin available:

    Plugin for osc52

    it should solve the issue

    0 讨论(0)
  • 2021-01-18 16:56

    You need to do two things.

    1. On your remote system, install a clipboard-aware Vim (and the X dependencies needed for clipboard support):

      $ sudo apt-get install vim-gtk
      
    2. On your local system, start your ssh session with X11 forwarding enabled:

      $ ssh -X user@hostname
      

      See $ man ssh for the security implications of X11 forwarding.

    0 讨论(0)
提交回复
热议问题