Skip to content
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

Copy/paste from system clipboard does not work on WSL2 #2132

Closed
patrick-kidger opened this issue Apr 16, 2022 · 11 comments
Closed

Copy/paste from system clipboard does not work on WSL2 #2132

patrick-kidger opened this issue Apr 16, 2022 · 11 comments
Labels
C-bug Category: This is a bug O-windows Operating system: Windows

Comments

@patrick-kidger
Copy link

Summary

As title. I don't see any obvious way to copy or paste from the Windows 10 clipboard when using Helix on Windows Subsystem for Linux (WSL) 2.

Reproduction Steps

When pasting:

  1. Start from the usual Windows 10 desktop.
  2. Open a terminal for WSL2.
  3. hx
  4. Copy something on Windows 10.
  5. i insert mode
  6. Attempt to paste it in. (In my case, right click.) Nothing happens.

Conversely, when selecting text inside Helix, I get the message "yanked main selection to system clipboard", but it cannot be pasted from the Windows environment. I assume it only gets as far as the wrapped Ubuntu.

In contrast Vim seems to handle this seamlessly. (Ironically I actually had to use Vim to copy-paste my config.toml in #2131.)

Helix log

No response

Platform

Windows WSL2, Ubuntu 20.04

Terminal Emulator

Hmm, whatever the WSL2 default is. Sorry!

Helix Version

git describe: 22.03-89-g450f3489; hx -V: helix 22.05-dev (450f348)

@patrick-kidger patrick-kidger added the C-bug Category: This is a bug label Apr 16, 2022
@the-mikedavis
Copy link
Member

Do the yank-to-system-clipboard and paste-from-system-clipboard commands work? Spacey to yank and Spacep to paste.

@patrick-kidger
Copy link
Author

patrick-kidger commented Apr 16, 2022

Nope; save behaviour as above.

They clearly get saved to some clipboard -- presumably the Ubuntu one -- as this system-yank/paste works within just Helix itself.

@the-mikedavis the-mikedavis added the O-windows Operating system: Windows label Apr 16, 2022
@NotTheDr01ds
Copy link

NotTheDr01ds commented Apr 16, 2022

This does work in Windows 10/WSL2, but requires additional user configuration.

clipboard.rs has several "system clipboard" checks, all of which will fail under WSL/Windows 10 without additional configuration:

  1. WAYLAND_DISPLAY variable set and wl-copy/wl-paste available.
  2. DISPLAY variable set and xclip available.
  3. win32yank.exe available (only in source at the moment; not released, see Reintroduce win32yank as a clipboard provider on Linux for WSL2 + Windows 10 #1912)

it's important to note that Windows 10 WSL does not support X11/Wayland out-of-the-box, so it's no surprise that Helix system clipboard support isn't working without xclip/wl-clipboard in WSL2/Windows 10.

However, this can be configured to work in several different ways:

  • Under Windows 11, WSL supports X11 and Wayland with clipboard integration. Simply install xclip OR wl-clipboard packages and Spacey and Spacep will copy to/paste from the Windows clipboard (as well as the X11 or Wayland clipboard).

  • Under Windows 10, you will need to install a third-party X server that supports Windows clipboard integration. VcXsrv is one. To configure:

    1. Install xclip in WSL
    2. Run XLaunch (the VcXsrv launcher) in Windows. Any mode can be used such as "Multiple Windows" or "Fullscreen".
    3. Keep the "Clipboard" option selected.
    4. Select "Disable Access Control"
    5. Set your DISPLAY correctly. In WSL2, that's typically export DISPLAY="$(hostname).local:0".
    6. Launch Helix, and clipboard integration should work as described above.
  • As an alternative under Windows 10, you can also:

    1. Build Helix from source
    2. Build or install win32yank.exe
    3. Launch Helix, and clipboard integration should work as described above.

Believe it or not, I've just tested all three of these approaches.

@nekodjin
Copy link

nekodjin commented Apr 16, 2022

Am I correct in thinking that

  1. win32yank.exe available (only in source at the moment; not released, see Reintroduce win32yank as a clipboard provider on Linux for WSL2 + Windows 10Reintroduce win32yank as a clipboard provider on Linux for WSL2 + Windows 10 #1912)

means that, there is already something in motion that will fix this issue? In other words, should we just sit still and wait patiently for it to be fixed?

@NotTheDr01ds
Copy link

@nekodjin Well, sort of. All three options have external dependencies, but the one with the fewest dependencies for Windows 10 involves either building from source or waiting patiently, yes.

Side note -- Looking at the source, I think it's possible to implement the system clipboard on WSL in a way that "just works" with a standard Windows 10/11 installation with no additional dependencies. But that's going to require an additional code change if so.

@kirawi
Copy link
Member

kirawi commented Nov 10, 2022

Addressed by #1912

@kirawi kirawi closed this as completed Nov 10, 2022
@einarpersson
Copy link

einarpersson commented Mar 4, 2023

Addressed by #1912

I have an issue currently where I am able to copy from helix to system (Win10) but not the other way around. I just installed helix on my Ubuntu distro under WSL2 (latest version). Any ideas on how I can troubleshoot? Any command I can run to get info for you to troubleshoot?

Running latest WSL2 (which has support for running GUIs natively etc), do I need to install any extra dependency or is it supposed to work out-of-the-box?

@kirawi
Copy link
Member

kirawi commented Mar 4, 2023

Yeah, you need to install win32yank.

@einarpersson
Copy link

win32yank

Ok, thank you! This should probably be added to the installation instructions

However:

Should I install it in WSL or on the Windows side?
This issue seems to suggest that it currently has to be installed on windows (eg. by using scoop) but this reddit comment seems to suggest that doing so adds a latency.

--

I went ahead and installed scoop, installed win32yank with it, and restarted.

Now pasting from system clipboard works in Helix, but as described above there is a latency of 2-3 seconds for just a single line of text.

@kirawi
Copy link
Member

kirawi commented Mar 5, 2023

It's unclear if there is a better solution. https://github.com/neovim/neovim/wiki/FAQ#how-to-use-the-windows-clipboard-from-wsl suggests that if Helix is also installed in WSL, you can install win32yank on the Linux side.

@wraiford
Copy link

In researching this, I also came across the currently still open #7219. Installed wl-clipboard via

sudo apt install wl-clipboard

fixed the issue for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug O-windows Operating system: Windows
Projects
None yet
Development

No branches or pull requests

7 participants