Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm editing a file in vim on a remote machine via ssh and I want to copy text out of the remote file and paste it into a vim instance running on my local machine. Is there an easy way to do this? I can use my terminal emulator's selection features to select text that is currently on the screen, but if my selection is larger than can fit on the screen, I'm out of luck.

share|improve this question

Open the remote file in the local vim session:

  :e scp://user@host/relative/path/from/home.txt
share|improve this answer
I like. Nice and simple. – Chev Jun 25 '14 at 21:48
Great tip! Can this scp:// be recognize elsewhere or it is VIM only? – Frozen Flame Sep 13 '15 at 12:48
@FrozenFlame: I believe it is app specific. BUT I wouldn't be surprised if a large DE like KDE or Gnome mandated support for this schema in every app. – progo Sep 13 '15 at 13:18

If you have sufficient permissions on the remote machine, you can add


to /etc/ssh/sshd_config and restart sshd with

sudo /etc/init.d/ssh restart

Then on your local machine add

ForwardX11 yes

to your ~/.ssh/config file

Then by running an X-aware vim on the remote machine (e.g., gvim -v), you can copy and paste to and from the X clipboard. Just visually select the text (e.g., using V) and yank it into the * register.


I forgot to include the part about setting SendEnv WINDOWID in your ~/.ssh/config, so I added that and moved the enabling of X forwarding from the command line (ssh -X option) to the ~/.ssh/config file (ForwardX11 yes).

share|improve this answer
I needed to install the xauth package for this to work on Debian. – leo Apr 28 '13 at 21:25
with this I can copy locally, and paste remotely. Is there a way to do also the other way around? thanks! – Paschalis Oct 27 '15 at 20:10

You must log in to answer this question.

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