Vim System Clipboard Support
WSL vim
-
Install
VcXsrv
(if it starts after installing, stop it). -
Start it using the newly installed program
XLaunch
(search in the start menu). -
Go with all the defaults options, and ensure the clipboard options are checked.
-
At the end, save the configuration to a file,
config.xlaunch
(use that to start it from now on). -
Put
export DISPLAY=localhost:0.0
in your.bashrc
in bash for Windows and run source ~/.bashrc in any open terminal. -
Ensure vim is installed using clipboard support.
vim --version | grep clipboard
should say+clipboard
, not-clipboard
. Also if you run the ex command:echo has('clipboard')
in vim and it says 0 it does not have clipboard support compiled in. -
If you don’t have clipboard support, install a vim package compiled with clipboard support, e.g.
apt-get install vim-gtk
orsudo dnf install vim-X11
As a bonus you should now be able to copy from and to your Windows clipboard from a remote machine by using SSH X forwarding (ssh -X … ). You can use xclip on the remote machine or if you use vim there you will again need to make sure the clipboard option is compiled into vim (e.g. install vim-gtk). You can probably also configure PuTTY to use your local X server in case you prefer using that for remote connections.
And for OSX: https://gist.github.com/romainl/96180b5b8e7722a7428c
System Clipboard Vim within TMUX within SSH session
Note
|
didn’t try it myself, yet. |
SSH X forwarding
-
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.
Terminal with OSC support
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()
Note
|
There is a plugin: https://github.com/greymd/oscyank.vim |