Connect remote vps with ssh.

ssh user@vps_ip

Edit a file in remote vps with vim and write a line

some text

In normal mode ,press yy ,how to paste some text to my local'vim?
And vice versa.

1.GUI flavour of VIM
In local vim whose os is debian:

vim --version | grep clipboard
+clipboard       +job             +path_extra      +user_commands
+eval            +mouse_dec       +statusline      +xterm_clipboard

In remote vim whose os is debian:

vim --version | grep clipboard
-clipboard       +iconv           +path_extra      -toolbar
+eval            +mouse_dec       +startuptime     -xterm_clipboard

Can't install vim-gtk in remote vim.

sudo yum  install -y vim-gtk
No package vim-gtk available.

2.Does the local system have an X server?
3.Are you using a GUI login session on the local system?
Desktop in local os is LXDE,enter into GUI login session.

  • More context is needed in the question for good answers. Is the remote system capable of running the GUI flavour of VIM, or NeoVIM? Is the local system? Does the local system have an X server? Are you using a GUI login session on the local system? There are at least three different ways of approaching this that I can think of, but they depend from the specifics of the scenario as to whether they are applicable.
    – JdeBP
    Sep 23, 2018 at 11:26

3 Answers 3


You can open the remote file by running vim scp://user@vps_ipi/remote_file and then open your local file with :e local_file, after that you can switch between the buffers with :bn and use the yy and p commands for copy and paste between the buffers.

I make a test opening a remote script, then copy all its content with ggVGy switched the buffer :bn and paste with P.


You can't even paste text from two different vim processes on the same host, so you can't from processes on different hosts.

What you can do is for short texts copy text from vim in one terminal window to the host's clipboard and paste it from the host's clipboard into the vim in the other terminal window. If you don't use a terminal window, you can also use tmux for similar effects. A ssh session inside emacs would also work, but you wouldn't ask about vim if you wanted to use emacs.

For longer texts I would copy them to/from the remote host with a porgram like scp and then use the file locally.


Use ssh -Y <hostname>, it will give ssh session the access to your local machine's clipboard. Make sure that X11Forwarding is enabled in /etc/ssh/sshd_config on remote machine.

Add to .vimrc on both machines:

 set clipboard=unnamedplus

This will allow using clipboard for yank operations by default. Now normal yank and paste will work across different machines. Alternatively, you can just use "+y to specify clipboard register for the same effect.

I guess the answer will not work in your case, as you don't have clipboard support in remote vim, but I wanted to add this answer for completeness as Google shows this question when searching for the ways how to copy text between machines using vim and it might be useful for other people.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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