我在ssh会话中使用tmux打开了vim。如何使vim将我的笔记本电脑系统剪贴板作为默认的复制粘贴?默认设置set clipboard=unamed
无效。两个系统都是Ubuntu。
如果您的终端模拟器支持,剪贴板集成功能(PASTE64/OSC52)非常有用。例如,iTerm2支持它(我不确定Ubuntu是否支持)。
将此功能添加到您的“远程”.vimrc
中。复制某些内容并运行:OscCopy
。即使在tmux会话中也可以正常工作。
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()
On your remote system, install a clipboard-aware Vim (and the X dependencies needed for clipboard support):
$ sudo apt-get install vim-gtk
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.