-
Notifications
You must be signed in to change notification settings - Fork 822
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
Comments
@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. |
@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). |
there ya go, fcbruce! You have your answer, use an X11 terminal. |
@fpqc @Blaisorblade Yes, it works. I installed Xming X Server for Windows and input the command |
For those who want to go the X server route, let me leave my notes here.
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 ( |
@robbiev Thank you for this! You are a lifesaver :) |
steps 1-5 worked for sublime (xming, not windows version of sublime) as well which may not be obvious to everyone |
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:
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 |
@lemongrassnginger I think this will start a new server process for every shell. For me it worked to copy |
So it does! Thanks for pointing that out. Will move to my Windows startup folder |
For people sitll looking for a solution I found a way that works without having to use X server. Thanks to bravekarma on reddit. Simply paste the following into your .vimrc or init.vim:
|
Ok I found a better way with both copy and paste working. I tested for neovim but with some modification will sort of work for vim also. curl -sLo /tmp/win32yank.zip https://github.com/equalsraf/win32yank/releases/download/v0.0.4/win32yank-x64.zip
unzip -p /tmp/win32yank.zip win32yank.exe > /tmp/win32yank.exe
chmod +x /tmp/win32yank.exe
sudo mv /tmp/win32yank.exe /usr/local/bin/ |
thank you. this is by far the best solution. |
The answer is based on this Neovim wiki page. |
If the solution with VcXsrv described by @robbiev stopped working when upgrading from WSL1 to WSL2, do the following: |
This is a brilliant answer, I think this works on my machine. However, if I ssh into a machine and try to yank those files to the clipboard, it no longer works? How to overcome this issue? |
These are nice workarounds, but considering who makes WSL. it is a wonder that I think @fcbruce and @alexcoca are still more correct than not that is should be an enhancement request or a bug report of some kind |
If you're on Windows 11, WSL has an X server configured out of the box.
This switches the installed options from |
Here's a translation into Lua for any Neovim users that come across this issue:
|
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.
The text was updated successfully, but these errors were encountered: