New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to copy text from vim to system clipboard? #892

fcbruce opened this Issue Aug 14, 2016 · 10 comments


None yet
8 participants

fcbruce commented Aug 14, 2016

I want to copy the text from vim to my windows apps(such as browser), I try to use "+y but it does not work. If there are some command can solve my problem? I know I can quit vim then cat file.txt and use mouse to do it, but I want to copy the text without mouse.


This comment has been minimized.

fpqc commented Aug 14, 2016

@fcbruce not in an easy and obvious way. You need to set up a pair of programs on both sides of the divide, one attached to the Windows clipboard, and one attached to the vim clipboard. If anyone has dealt with this problem, it might be something like PuTTY or cygwin/cygterm, which might have something built in, since they bridge this kind of divide inherently.


This comment has been minimized.

Blaisorblade commented Aug 14, 2016

@fpqc Note that "+y connects to the X11 clipboard, not to the Vim one, making this easier to handle. Indeed this already works in MSYS2, and without an X-server — install Git for Windows, start Git Bash, use vim inside. (Not sure how much magic is required for that though).


This comment has been minimized.

fpqc commented Aug 14, 2016

there ya go, fcbruce! You have your answer, use an X11 terminal.


This comment has been minimized.

fcbruce commented Aug 15, 2016

@fpqc @Blaisorblade Yes, it works. I installed Xming X Server for Windows and input the command export DISPLAY=:0 in the bash of linux subsystem. Thank you very much! ^_^

@fcbruce fcbruce closed this Aug 15, 2016


This comment has been minimized.

robbiev commented Jan 28, 2017

For those who want to go the X server route, let me leave my notes here.

  1. Install VcXsrv (I found that Xming is outdated on sourceforge and the new version is donationware)
  2. If it starts after installing, stop it
  3. Start it using XLaunch (search in the start menu), go with all the defaults (ensure the clipboard options are checked)
  4. At the end, save the configuration to a file (use that to start it from now on)
  5. Put export DISPLAY=localhost:0.0 in your .bashrc in bash for Windows (and run the command in any open bash windows). The reason I explicitly say localhost is that this makes SSH X forwarding work, see below.
  6. Ensure vim is installed using clipboard support. vim --version | grep clipboard should say +clipboard, not -clipboard. Also if you run the ex command :echo has('clipboard') in vim and it says 0 it does not have clipboard support compiled in. If you don't have clipboard support, install the vim-gtk package (apt-get install vim-gtk).
  7. It should now work

As a bonus you should now be able to copy from and to your Windows clipboard from a remote machine by using SSH X forwarding (ssh -X ... ). You can use xclip on the remote machine or if you use vim there you will again need to make sure the clipboard option is compiled into vim (e.g. install vim-gtk). You can probably also configure PuTTY to use your local X server in case you prefer using that for remote connections.


This comment has been minimized.

ggada commented Apr 6, 2017

@robbiev Thank you for this! You are a lifesaver :)


This comment has been minimized.

JonahKlimack commented Jul 26, 2017

steps 1-5 worked for sublime (xming, not windows version of sublime) as well which may not be obvious to everyone


This comment has been minimized.

lemongrassnginger commented Oct 25, 2017

for those using the VcXsrv approach by @robbiev, I was trying to find a way to start VcXsrv without having to start it manually by the XLaunch GUI.

Adding a line like this to ~/.bashrc works for me:

# start Xserver for shared clipboard
"/mnt/c/Program Files/VcXsrv/xlaunch.exe" -run config.xlaunch

It requires a config file, which can be generated from the last screen of the XLaunch GUI, just save it in the same folder as the xlaunch executable


This comment has been minimized.

Ossur commented Nov 9, 2017

@lemongrassnginger I think this will start a new server process for every shell. For me it worked to copy config.xlaunch to %USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup so that Windows launches an instance at startup.


This comment has been minimized.

lemongrassnginger commented Nov 10, 2017

So it does! Thanks for pointing that out. Will move to my Windows startup folder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment