Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

2 Answers 2

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. –  Alex Ford Jun 25 at 21:48

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

AcceptEnv WINDOWID

to /etc/ssh/sshd_config and restart sshd with

sudo /etc/init.d/ssh restart

Then on your local machine add

ForwardX11 yes
SendEnv WINDOWID

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.

Edit

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.