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

[WSL] Copy doesn't work #1365

Open
bytemain opened this issue Aug 1, 2019 · 20 comments
Open

[WSL] Copy doesn't work #1365

bytemain opened this issue Aug 1, 2019 · 20 comments

Comments

@bytemain
Copy link

bytemain commented Aug 1, 2019

Description of the problem or steps to reproduce

In the WSL(Windows Subsystem Linux), Select something and press Ctrl+C

the result show:
image

but actually copy failed.

image
WSL can use the windows' clip.exe to copy content.

Specifications

You can use micro -version to get the commit hash.

Commit hash: 3a8898d
OS: Arch WSL2(Linux version 4.19.55-microsoft-standard (oe-user@oe-host) (gcc version 7.3.0 (GCC)) #1 SMP Fri Jun 28 20:53:12 UTC 2019)
Terminal: Cmder

@theAkito
Copy link
Contributor

Can confirm.

@oOBoomberOo
Copy link

Can also confirm.
OS: Elementary OS 5.1, default Terminal.

@wizel10
Copy link

wizel10 commented Jul 30, 2020

not complaining. came here for this exact same issue only to realize it was open 1 year ago and nothing done...
Either it was solved some where else or will not be solve.

@zyedidia
Copy link
Owner

zyedidia commented Jul 30, 2020

I'm not sure how micro can detect that it is running in WSL rather than Linux, and therefore should use clip.exe instead of xclip/xsel. In addition clip.exe appears to only support copying and not pasting. Also, it appears support for OSC52 was recently merged into the WSL terminal (microsoft/terminal#5823), and new versions of micro (nightly builds) support this if you set the clipboard option to terminal. It seems the WSL terminal only supports copying with OSC52 and not pasting (for security reasons).

Unfortunately I don't use WSL (maybe I should install it though) so it is difficult for me to test.

Perhaps it is possible to make a script on your system called xclip which performs Windows commands to copy/paste. For example, I found this Github repository which seems to do this: https://github.com/Konfekt/xclip-xsel-WSL.

@wizel10
Copy link

wizel10 commented Jul 31, 2020

Thanks for the reply. I've look at different options with no avail.
copy send command: xclip -in -selection clipboard, but don't know how to read the clipboard. The Github repo you pointed, didn't work for same reason, no access to the clipboard.
If you want me to try a few thinks, let me know. More than open to help.

@wizel10
Copy link

wizel10 commented Jul 31, 2020

I was intrigued with a different behavior in nano vs micro.
In nano, selection through mouse shows a "pale white" while selection in micro shows a "solid white".
In nano, the "solid white" doesn't copy and thought copy-paste was more related to text selection rather than the proper commands.
I did set mouse to false in settings and copy-paste works as expected in WSL2.

For anyone with similar issue:
settings.json:
{
"autosu": true,
"mouse": false,
"tabsize": 2,
"tabstospace": true
}

No need to install xclip or xsel and ctr-c ctrl-v works perfect.
Note: all mouse functionality is gone inside the editor (same as in nano).
Not an ideal solution, but somewhat acceptable.

@zyedidia
Copy link
Owner

zyedidia commented Aug 2, 2020

Yes it's always possible to disable the mouse in micro and fall back to your terminal emulator's selection and copy/paste. The drawback is that the terminal emulator has no concept of multiple splits holding different text, and line numbers not being part of the text.

@0x4a
Copy link

0x4a commented Oct 16, 2020

I got Copy (and Paste) working by uninstalling xclip, and providing this as "xclip" in my path (~/.local/bin):

#!/bin/bash
clip.exe <&0

@DePingus
Copy link

DePingus commented Jan 15, 2021

I got Copy (and Paste) working by uninstalling xclip, and providing this as "xclip" in my path (~/.local/bin):

#!/bin/bash
clip.exe <&0

Thanks for this. It sorta works, but isn't a perfect solution. I'm using Debian 1.2.0.0 (from the Microsoft Store) on Windows 10 1909 with WSL2 and Windows Terminal 1.4.3243.0.

With your ~/.local/bin/xclip, paste from Micro to Micro has issues. The standard Ctrl+c then Ctrl+v doesn't work. Ctrl+c then Ctrl+Shift+v will work, but it will only paste to the cursor; i.e., not if you have something highlighted you're trying to replace. If you try it, you lose whatever is in the clipboard and have to copy it again. You also lose the contents of the clipboard if you accidentally hit Ctrl+v (instead of Ctrl+Shift+v).

A couple more notes to those trying this: Don't forget to chmod +x ~/.local/bin/xclip. Also, in Debian, the Windows paths aren't exposed in the environment. So add them to your bash profile or simply hard code the path to /mnt/c/Windows/System32/clip.exe in the script.

@mateuszkozakiewicz
Copy link

I got Copy (and Paste) working by uninstalling xclip, and providing this as "xclip" in my path (~/.local/bin):

#!/bin/bash
clip.exe <&0

This causes clipboard to be cleared every time micro is opened for me.
Doing Ctrl+e and typing set clipboard terminal makes copy/paste work fine on Windows Terminal Preview.

@Gorthog
Copy link

Gorthog commented Apr 13, 2021

Doing Ctrl+e and typing set clipboard terminal makes copy/paste work fine on Windows Terminal Preview.

Works well with Windows Terminal 1.6.10571.0

@CoolingTool
Copy link

I got Copy (and Paste) working by uninstalling xclip, and providing this as "xclip" in my path (~/.local/bin):

#!/bin/bash
clip.exe <&0

I had to move the script to /usr/local/bin because ~/.local/bin wasn't in the path when doing wsl micro, works perfectly so far

@Gorthog
Copy link

Gorthog commented May 2, 2021

not sure using clip.exe is a good idea. It corrupts the text in certain scenarios. See microsoft/WSL#4852

@Gorthog
Copy link

Gorthog commented May 2, 2021

Personally, I found ctrl +e and set clipboard terminal to work perfectly fine, but if for someone it's not working well please see my comment for an alternative tool that works better than clip.exe: microsoft/WSL#4852 (comment)

@frankydee
Copy link

frankydee commented Dec 17, 2021

Personally, I found ctrl +e and set clipboard terminal to work perfectly fine, but if for someone it's not working well please see my comment for an alternative tool that works better than clip.exe: microsoft/WSL#4852 (comment)

@sinapis, since ctrl +e and set clipboard terminal didn't work for me, I installed utf8clip according to your instruction in your WSL comment.

Copy from a Windows app and paste in micro now works, but copy in micro and paste in micro doesn't (it always pastes what I have last copied in Windows). Is there any trick to copy in micro and paste in micro?

@Gorthog
Copy link

Gorthog commented Dec 17, 2021

@frankydee try to set clipboard to internal.
If that doesn’t solve the issue try external. When setting external you will also need to configure someplace which clipboard tool should be used. Another option is to create a “fake” xclip just like you see in this thread above but call utf8clip inside the actual script

@kvnloughead
Copy link

I've still not found a viable solution, although my experience is a bit different than what's been described so far. Using Ubuntu 20.04 WSL2, I have no trouble copy/pasting with micro when it's opened in Windows terminal. Everything seems to work fine with the clipboard set to terminal.

However, this is not the case in VSCode's integrated terminal. In there, copying gives a success message but does not copy. Pasting still works though.

I've tried turning mouse off, and I've tried the trick with the xclip file, but no success.

@mateuszkozakiewicz
Copy link

However, this is not the case in VSCode's integrated terminal. In there, copying gives a success message but does not copy. Pasting still works though.

I have not tested this but try https://stackoverflow.com/a/69928270

@kvnloughead
Copy link

Thanks @mateuszkozakiewicz , but maybe I wasn't as clear as I should have been. Copy/pasting works fine in VSCode integrated terminal accept when I have micro opened in it.

@fmajestic
Copy link

This will probably be fixed in the next release since we got 03ae049

But in the meantime, I found this to work:

#!/bin/sh

if [ "$1" = "-in" ]; then
  powershell.exe '$Input | Set-Clipboard'
else
  powershell.exe Get-Clipboard
fi

Put it in a file called xclip somewhere on your path, and don't forget to make it executable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests