terminal icon indicating copy to clipboard operation
terminal copied to clipboard

[WSL] Newlines when copying from console

Open strarsis opened this issue 8 years ago • 34 comments

  • Your Windows build number: Microsoft Windows [Version 10.0.16299.192]

  • What you're doing and what's happening: Select text in a (WSL/Bash on Windows) console using the mouse and copying it using right mouse button.

  • What's wrong / what should be happening instead: The resulting text (when pasted) got no newlines but lots of whitespace between the lines instead.

strarsis avatar Jan 23 '18 23:01 strarsis

Is there are workaround for this? It makes copying from the terminal very difficult, and I'm finding myself opening WSL directly just to copy text out.

FilipBB avatar Jul 25 '19 15:07 FilipBB

@FilipBB: There are some workarounds:

  1. Pipe the command output into a text file, open the text file in a Windows editor to copy its contents.
  2. Copy the tmux (or screen or whatever terminal multiplexer is used) buffer into clipboard using a shortcut/built-in command.

strarsis avatar Jul 25 '19 18:07 strarsis

Thanks, unfortunately it's a little cumbersome for remote work, you'd have to copy the file back to your local machine, and I can't get tmux buffer copy on the remote side to work. Hopefully this issue gets fixed in the near future.

FilipBB avatar Jul 31 '19 17:07 FilipBB

Is there any plan to fix it?

CzBiX avatar Sep 04 '19 12:09 CzBiX

Looks like this bug fell under the radar.

@strarsis are you holding shift while you're copying (via right click)? In conhost, when the user holds shift while copying, we won't "trim whitespace", leaving the space at the end of the line as part of the copied text. This also applies to using ctrl+shift+c for copying from conhost.

Additionally, what are you pasting into? Notepad, or some other commandline application running in the console?

Also cc'ing @carlos-zamora

zadjii-msft avatar Sep 04 '19 13:09 zadjii-msft

Just left click and drag to select multiline text, then right click to copy, then Ctrl+V to paste in notepad will get single line text include a lots of space without newline.

And paste to another place will get the same result. But the same operations works well in the original WSL terminal without issue.

example result:

server {                                                                                                                  listen 443 ssl http2;                                                                                                   server_name example.com;                                                                                                                                                                                                                   include snippets/log.conf;                                                                                              include snippets/auth.conf;                                                                                                                                                                                                                     location / {                                                                                                              include proxy_params;                                                                                                   proxy_pass http://10.8.1.1:8888;                                                                                      }                                                                                                                     }

CzBiX avatar Sep 04 '19 13:09 CzBiX

@zadjii-msft: Damn, I have indeed holding down the shift key down while right clicking (for copying). I need to hold down the shift key for the initial multiline text selection, but when I right click I have to release the Shift key first.

strarsis avatar Sep 04 '19 14:09 strarsis

I have the copyOnSelect feature enabled so I don't have the shift key pressed at any given time. Following are the results from copying text from different profiles. WSL and git bash profiles seem to have problems.

dotnet --info from PS:

PS C:\Users\Coskun> dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   3.0.100
 Commit:    04339c3a26

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.18362
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.0.100\

Host (useful for support):
  Version: 3.0.0
  Commit:  7d57652f33

.NET Core SDKs installed:
  2.2.402 [C:\Program Files\dotnet\sdk]
  3.0.100 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

dotnet --info from cmd:

C:\Users\Coskun>dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   3.0.100
 Commit:    04339c3a26

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.18362
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.0.100\

Host (useful for support):
  Version: 3.0.0
  Commit:  7d57652f33

.NET Core SDKs installed:
  2.2.402 [C:\Program Files\dotnet\sdk]
  3.0.100 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

dotnet --info from git bash:

Coskun@CS:~ $ dotnet --info                                                                                             .NET Core SDK (reflecting any global.json):                                                                              Version:   3.0.100                                                                                                      Commit:    04339c3a26                                                                                                                                                                                                                          Runtime Environment:                                                                                                     OS Name:     Windows                                                                                                    OS Version:  10.0.18362                                                                                                 OS Platform: Windows                                                                                                    RID:         win10-x64                                                                                                  Base Path:   C:\Program Files\dotnet\sdk\3.0.100\                                                                                                                                                                                              Host (useful for support):                                                                                                Version: 3.0.0                                                                                                          Commit:  7d57652f33                                                                                                                                                                                                                           .NET Core SDKs installed:                                                                                                 2.2.402 [C:\Program Files\dotnet\sdk]                                                                                   3.0.100 [C:\Program Files\dotnet\sdk]                                                                                                                                                                                                         .NET Core runtimes installed:                                                                                             Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]                               Microsoft.AspNetCore.All 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]                                Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]                               Microsoft.AspNetCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]                                Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]                                Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]                                     Microsoft.NETCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]                                      Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]                                      Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]                                                                                                                                              To install additional .NET Core runtimes or SDKs:                                                                         https://aka.ms/dotnet-download

lsb_release -a from WSL:

coskun@CS:~$ lsb_release -a                                                                                             No LSB modules are available.                                                                                           Distributor ID: Ubuntu                                                                                                  Description:    Ubuntu 19.04                                                                                            Release:        19.04                                                                                                   Codename:       disco

CoskunSunali avatar Oct 05 '19 12:10 CoskunSunali

I have copyOnSelect disabled, using mouse right-click for copy paste, not holding shift key.

  • dotnet --info output in cmd and PowerShell pastes correctly into VS Code
  • dir output in cmd and PowerShell pastes incorrectly into VS Code
    • trailing whitespace, no newlines; same issue as with WSL

This makes copy paste from Microsoft Terminal useless.

gitfool avatar Oct 05 '19 19:10 gitfool

still not working properly in Version: 0.5.2762.0 copying a text from WSL console when using scroll-back is loosing CR or LF

hteibler avatar Oct 11 '19 07:10 hteibler

Copying with Ctrl+Shift+C will result in a single line in either PowerShell or WSL.

Copying with right click will not result a single line in either WDL or PowerShell.

Tested on the latest version on master and on the latest from the store (0.7).

giggio avatar Nov 27 '19 16:11 giggio

It seems the text is copied as a table instead of text with new line characters. Pasting into something like MS Excel and copying back out again to my text editor produces the expected result.

adamncasey avatar Apr 23 '20 12:04 adamncasey

For me, copying from Windows terminal - WSL - ssh - tmux to Windows with correct white spaces works (only) by: select text with the mouse while holding shift and copy with Ctrl+ Insert

jan-glx avatar Apr 28 '20 14:04 jan-glx

Same issue happens to me. I can Copy - Paste from WSL Terminal, but when Paste, it doesn't has new line. It's just inline text. No new line. Any update on this issue? Is there any work around so I can copy - paste with new line (not inline)? image

P.S: I have enough experience using Linux and currently moving to Windows. I have habit of using Ctrl + Shift + C for Copy and Ctrl + Shift + V for Paste.

fendis0709 avatar Nov 02 '20 16:11 fendis0709

@fendis0709: Right, currently one has to just drag and select the text, while not holding the Shift key to avoid this line endings issue.

strarsis avatar Nov 02 '20 19:11 strarsis

So, is there an intention to fix this or is using ctrl-shift-c for copy functioning as designed? Because this is annoying.

lukeschlather avatar Dec 18 '20 19:12 lukeschlather

@lukeschlather - not sure if addresses your needs, but the behavior of copy is configurable (see here: https://docs.microsoft.com/en-us/windows/terminal/customize-settings/actions#copy). Among the settings, you can decide where the new lines should be preserved or not.

Don-Vito avatar Dec 23 '20 13:12 Don-Vito

@Don-Vito where is the settings.json file located? The docs are somewhat vague.

Regardless, stripping newlines when copying seems like a bad default. Is that even a feature people want?

lukeschlather avatar Dec 23 '20 18:12 lukeschlather

by default

if we are doing that by default, it is a bug.

DHowett avatar Dec 23 '20 19:12 DHowett

Isn't that what this bug is? I just installed WSL2 Ubuntu for the first time and I am seeing this bug. Which has been open for two years and seems like it ought to be a fairly straightforward fix.

lukeschlather avatar Dec 23 '20 19:12 lukeschlather