Terminal: [WSL] Newlines when copying from console

Created on 24 Jan 2018  路  15Comments  路  Source: microsoft/terminal

  • 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.

Area-Interaction Issue-Bug Product-Conhost

Most helpful comment

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).

All 15 comments

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

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.

Is there any plan to fix it?

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

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;                                                                                      }                                                                                                                     }

@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.

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

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.

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

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).

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.

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

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: Right, currently one has to just drag and select the text, while _not_ holding the Shift key to avoid this line endings issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alabuzhev picture alabuzhev  路  3Comments

Wid-Mimosa picture Wid-Mimosa  路  3Comments

dev-logan picture dev-logan  路  3Comments

zadjii-msft picture zadjii-msft  路  3Comments

mrmlnc picture mrmlnc  路  3Comments