One of the advantages of console Vim is, that you can use it in a console SSH session. This way you can work on a remote machine also on slow connections and don’t need laggy remote desktop software. This is even more important if the remote machine is a headless server without a desktop at all.

But when you want to use copy/paste between the remote machine and the local machine this is a problem:

  1. Vim by default uses internal registers. The default register without specifying one is "". E.g. when doing a yy (yank current line). As a Vim users you know that you can also yank to a named register. E.g. "ayy will yank to register "a instead of "". The special register "* is the system clipboard. This way you can exchange data between Vim and other applications: "*yy
  2. By enabling X11 forwarding in SSH you can “connect” the system clipboard between the remote and the local machine:
    1. Enable X11Forwarding on the SSH server side in /etc/ssh/sshd.conf
    2. Use the -Y option of for ssh client to enable it when connecting: ssh -Y your_server"

Now you can copy in the remote Vim using ‘“*yy’ and paste it locally in Vim using ‘“*p’ or paste it in any GUI app using C-V.

In the following screenshot you can see how I copied a line of LaTeX code from the remote machine in the right window to the local machine in the left window. The KDE Klipper tool at the bottom right also shows the clipboard contents.



comments powered by Disqus