8

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).

2 Answers 2

1

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.

0

On MacOS, when SSH from machine A to machine B and using vim in machine B, I add this to my .vimrc in machine B:

nmap yr :call system("ssh $machineA_IP pbcopy", @*)<CR>

That way, in normal mode, content of * register if vim@machine_B is copied to machine A's local clipboard, assuming you have setup Vim correctly with +clipboard and * register

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .