helix-editor / helix

A post-modern modal text editor.
https://helix-editor.com
Mozilla Public License 2.0
33.54k stars 2.49k forks source link

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

Closed patrick-kidger closed 1 year ago

patrick-kidger commented 2 years ago

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 (450f3489)

the-mikedavis commented 2 years ago

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

patrick-kidger commented 2 years ago

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.

NotTheDr01ds commented 2 years ago

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 #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:

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

nekodjin commented 2 years ago

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 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 commented 2 years ago

@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 commented 1 year ago

Addressed by #1912

einarpersson commented 1 year ago

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 commented 1 year ago

Yeah, you need to install win32yank.

einarpersson commented 1 year ago

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 commented 1 year ago

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 commented 7 months ago

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.