honzajscz
honzajscz

Reputation: 3107

WT: Paste multiple lines to Windows Terminal without executing

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?

Upvotes: 20

Views: 20118

Answers (5)

patfinder
patfinder

Reputation: 31

  • Dec 2024: For me, just paste by right-click. The content (multi-lines) is pasted to the Powershell prompt and waiting for edit (without executing right away).

Upvotes: 0

js2010
js2010

Reputation: 27516

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.

Upvotes: 0

Mesum Raza Hemani
Mesum Raza Hemani

Reputation: 1

Just tick the check box for highlighted setting

enter image description here

Upvotes: -9

honzajscz
honzajscz

Reputation: 3107

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

Upvotes: 16

apena
apena

Reputation: 2331

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.

Upvotes: -4

Related Questions