micro: [WSL] Copy doesn't work

Description of the problem or steps to reproduce

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

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

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 19
  • Comments: 20 (3 by maintainers)

Most upvoted comments

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.

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

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

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: https://github.com/microsoft/WSL/issues/4852#issuecomment-606497383

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

Can confirm.

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.

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 (https://github.com/microsoft/terminal/pull/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.

This will probably be fixed in the next release since we got https://github.com/zyedidia/micro/commit/03ae049c0fe5862ca6010474dd775656bd6e5b86

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

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.

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.

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.