Linux – Copy/paste across vim without X

clipboardlinuxterminalvim

In vim, "+p pastes from the system clipboard. However, when working remotely over SSH on a non-GUI box, this is not available.

Is it possible to implement copy/paste in this environment?

Merely copying text from the terminal is not sufficient, because it will also copy stuff that's beyond the scope of the file (for example, if using tmux, it copy the full screen because it's all plain text).

Best Answer

One workaround is using (remotely accessed) scratch files to transfer the text:

In case you can SSH back to your own system, you can just :split scp://hostname/path/to/file, put the yanked text there, and :write.

If you can just use SSH from your system to the server box, open Vim locally and access the scratch file from the server: vim scp://server/path/to/file (or just use scp directly).

This is all enabled by the netrw plugin that ships with Vim.

Related Question