10

In the original PowerShell console it was possible to paste and edit multiline commands before executing it

For example this multiline script:

Write-Host "===== 1 ====="
Write-Host "===== 2 ====="
Write-Host "===== 3 ====="
Write-Host "===== 4 ====="

results in the following output

powershell 7 console with multiline paste

Unfortunately, in the Windows Terminal pasting of the same script results in a very different output

enter image description here

Any ideas how to "fix" the multiline pasting in the Windows Terminal?

honzajscz
  • 2,850
  • 1
  • 27
  • 29

4 Answers4

9

The solution for me was to just comment out a line in the terminal setting.json with { "command": "paste", "keys": "ctrl+v" }

enter image description here

And then it works - here the expected output

working output

Edit:

After uncommenting the Ctrl+V chord in the settings.json, the paste functionality is ensured by the PSReadLine module (see Get-PSReadLineKeyHandler -Chord ctrl+v) but Ctrl+V will stop to work in other shells - use Shift+Ctr+V instead

honzajscz
  • 2,850
  • 1
  • 27
  • 29
  • great solution - sort of feels counter intuitive that commenting out the ctl+v line in settings means that ctl+v now works ... but it does work so I'm happy! What do you mean when you refer to "the Ctrl+V chord in the settings.json"? – whytheq May 06 '23 at 16:49
  • 1
    It means the text in the red box – honzajscz May 15 '23 at 12:25
0

Also pasting with right click will run each line right away. Also control-v makes it easier to paste unicode characters (at least in cmd/powershell console). Note that control-v gets remapped with psreadline's emacs edit mode option.

js2010
  • 23,033
  • 6
  • 64
  • 66
-4

I know it is not ideal you can convert linebreaks to semicolons

Write-Host "===== 1 =====";Write-Host "===== 2 =====";Write-Host "===== 3 =====";Write-Host "===== 4 ====="

Online converter here.

apena
  • 2,091
  • 12
  • 19
-7

Just tick the check box for highlighted setting

enter image description here

  • 1
    The question is about the "Windows Terminal" application, not about the console executable. – mmseng Oct 21 '21 at 18:19