Reproduce multi-line paste handling from Powershell host #10849

Closed
opened 2026-01-31 02:31:53 +00:00 by claunia · 2 comments
Owner

Originally created by @nixtar on GitHub (Oct 1, 2020).

Description of the new feature/enhancement

In powershell.exe you can paste multiple lines using ctrl+v and the shell will give you the lines in an editable fashion, almost as if ` was appended to each line.
Currently Windows Terminal handles pasting with ctrl+v with the same behaviour as pasting using right click in powershell.exe and executes each line separately.

EG:
If you copy and paste using ctrl+v the following block into powershell.exe it gets handled as a single block and you can use arrow keys to move up and change the lines.

$a = "Foo"
$b = "Bar"
Write-Host "$a $b"

to powershell.exe:

PS D:\> $a = "Foo"
>> $b = "Bar"
>> Write-Host "$a $b"

To Windows Terminal:

PS D:\> $a = "Foo"
PS D:\> $b = "Bar"
PS D:\> Write-Host "$a $b"

This comes in handy for me when copying snippets of powershell from other projects or from websites and I need to adjust them slightly without needing to first paste into Notepad, VSCode or ISE to edit.

Perhaps a setting to toggle this kind of pasting behaviour in the profile or a multiline paste command to handle this situation?
It would also make pasting multiple lines more "safe" as you need to hit return to execute the lines.

Originally created by @nixtar on GitHub (Oct 1, 2020). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING: 1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement. 2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement. 3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number). 4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement. 5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement. All good? Then proceed! --> # Description of the new feature/enhancement In powershell.exe you can paste multiple lines using ctrl+v and the shell will give you the lines in an editable fashion, almost as if ` was appended to each line. Currently Windows Terminal handles pasting with ctrl+v with the same behaviour as pasting using right click in powershell.exe and executes each line separately. EG: If you copy and paste using ctrl+v the following block into powershell.exe it gets handled as a single block and you can use arrow keys to move up and change the lines. ```powershell $a = "Foo" $b = "Bar" Write-Host "$a $b" ``` to powershell.exe: ```none PS D:\> $a = "Foo" >> $b = "Bar" >> Write-Host "$a $b" ``` To Windows Terminal: ```none PS D:\> $a = "Foo" PS D:\> $b = "Bar" PS D:\> Write-Host "$a $b" ``` This comes in handy for me when copying snippets of powershell from other projects or from websites and I need to adjust them slightly without needing to first paste into Notepad, VSCode or ISE to edit. Perhaps a setting to toggle this kind of pasting behaviour in the profile or a multiline paste command to handle this situation? It would also make pasting multiple lines more "safe" as you need to hit return to execute the lines.
claunia added the Issue-QuestionNeeds-Tag-FixResolution-Answered labels 2026-01-31 02:31:53 +00:00
Author
Owner

@KalleOlaviNiemitalo commented on GitHub (Oct 1, 2020):

Bracketed paste mode https://github.com/microsoft/terminal/issues/395 should eventually fix this properly.

You can also remove the Ctrl+V binding in settings.json of Windows Terminal, so that the Ctrl+V is passed to PowerShell, where PSReadLine then pastes the text from the Windows clipboard without executing it. I don't think that can work over SSH, though.

@KalleOlaviNiemitalo commented on GitHub (Oct 1, 2020): Bracketed paste mode <https://github.com/microsoft/terminal/issues/395> should eventually fix this properly. You can also remove the Ctrl+V binding in `settings.json` of Windows Terminal, so that the Ctrl+V is passed to PowerShell, where PSReadLine then pastes the text from the Windows clipboard without executing it. I don't think that can work over SSH, though.
Author
Owner

@DHowett commented on GitHub (Oct 1, 2020):

Thanks @KalleOlaviNiemitalo; that pretty much sums it up.

PowerShell outside of Windows Terminal handles pasting on its own, and until #395 lands (plus PSReadline's https://github.com/PowerShell/PSReadLine/issues/579), your best bet is to unbind ^V in your local settings for local clipboard paste (if you only use PowerShell) or rebind PSReadline's Paste to another key.

@DHowett commented on GitHub (Oct 1, 2020): Thanks @KalleOlaviNiemitalo; that pretty much sums it up. PowerShell outside of Windows Terminal handles pasting on its own, and until #395 lands (plus PSReadline's https://github.com/PowerShell/PSReadLine/issues/579), your best bet is to unbind ^V in your local settings for local clipboard paste (if you only use PowerShell) or rebind PSReadline's Paste to another key.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#10849