Xshell Knowledge Base

Copying from ViM to Windows Clipboard

Last modified: Wednesday, November 15, 2017 12:38 AM

While using Xshell, or a similar terminal program, and in ViM, you are unable to copy yanked text nor the selection in mouse mode to the Windows Clipboard. This can be frustrating if you need to copy something from ViM into a Windows application such as notepad. However, using vim-x11, we can circumvent this issue and successfully copy the contents of ViM to the Windows Clipboard.

In ViM, the * and + registers are the registers which reference the system clipboard. The clipboard in this case, however, is the clipboard of the remote system, not the Windows Clipboard we desire. If you're utilizing X11 in your PC by using Xmanager, we can use the connection between the remote system and Windows.

  1. If your remote system does not have the vimx command, you'll need to install vim-X11 in your remote system first.  The result of 'vim --version |grep clipboard' should contain '+clipboard'

  2. Install Xmanager.

  3. Run Xshell and connect to the server using the SSH protocol with X11 forwarding.

  4. Run vimx instead of vim or vi.

  5. Select the area you want to copy to the clipboard using the vim selection method.

  6. Place the contents into the clipboard register using the "+y key strokes.

  7. Paste the contents in your desired Windows application suh as notepad.