Terminal: Reproduce multi-line paste handling from Powershell host

Created on 1 Oct 2020  路  2Comments  路  Source: microsoft/terminal

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.

Issue-Question Needs-Tag-Fix Resolution-Answered

All 2 comments

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.

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

privacyguy123 picture privacyguy123  路  131Comments

yanglr picture yanglr  路  235Comments

patriksvensson picture patriksvensson  路  143Comments

cinnamon-msft picture cinnamon-msft  路  62Comments

Paul-Weisser picture Paul-Weisser  路  71Comments