These scripts allows you to use vim in a remote machine via ssh, and being capable of sharing the local clipboard with vim's 0 register (which is the one used by default by yank/paste).
To make it work:
-
In your local machine, run
clipboard-server.py
, which uses flask to create a simple REST API exposing only the/
endpoint, listening onlocalhost:11223
GET /
will retrieve the system clipboard of the machine in which the server is run, in form of a JSON with the field"content"
.POST /
expects a JSON with a field named"content"
containing one string, which is placed in the system clipborad of the machine running the server. -
Copy the content of the
vimrc
file to the end of your~/.vimrc
in the remote machine. Follow the commments for customization. This script makes use of vim's python extension, which has to be enabled (you can check if it is enabled withvim --version | grep python
) -
Connect via ssh to your remote machine, while setting up a remote tunnel:
ssh -R11223:localhost:11223 user@remote.ip
This leaves a socket listening in port 11223 in the remote machine, and forwards all the traffic to that port to your local Flask server. I.e.: in your remote machine you can make HTTP GET and POST requests to
localhost:11223
and your local server will answer. As bonus, the connection is encrypted by the tunnel. -
Open
vim
in the remote machine.Select some text in vim (eg: using
V
) and then pressRY
. The contents of the selection will be sent to your local flask sever, which will put them in the system clipboard, from which you can paste it into any other app in your local host.In your local machine select some text in any app and copy it to your system clipboard. Then, in the remote vim use
KP
to retrieve this text and paste it. The text is also placed in0
register, so you can paste it again pressingp
orP
.