System Clipboard Vim within TMUX within SSH session

≯℡__Kan透↙ 提交于 2020-04-07 03:29:44

问题


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 isn't working. Both systems are Ubuntu in case that matters.


回答1:


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.




回答2:


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




回答3:


For the osc52 copy, there's plugin available:

Plugin for osc52

it should solve the issue



来源:https://stackoverflow.com/questions/45247929/system-clipboard-vim-within-tmux-within-ssh-session

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!