Pasting a block of text runs each line seperately #18383

Closed
opened 2026-01-31 06:12:17 +00:00 by claunia · 4 comments
Owner

Originally created by @kilasuit on GitHub (Sep 3, 2022).

Windows Terminal version

1.14.2282.0

Windows build number

Microsoft Windows NT 10.0.25182.0

Other Software

PowerShell 7.2.6 with PSReadline 2.1.0
PowerShell 7.3.0-preview.7 with PSReadline 2.2.6

Steps to reproduce

As per this issue in the PowerShell Repo

Windows Terminal only allows pasting of a block of text which it then attempts to run line by line no matter how you try pasting as neither CTRL + V, CTRL + SHIFT + V, SHIFT + INSERT or right click paste worked for me

Expected Behavior

One of these pasting methods should paste this as a single block which can then be run by the user as a whole block, not breaking user experience expectations

Actual Behavior

Windows terminal pastes in each line one by one whilst attempting to run individual lines from the pasted text
This wrongly creates in PowerShell a Parser error, due to the lack of ability to paste all as a single block before running it as a whole block

Originally created by @kilasuit on GitHub (Sep 3, 2022). ### Windows Terminal version 1.14.2282.0 ### Windows build number Microsoft Windows NT 10.0.25182.0 ### Other Software PowerShell 7.2.6 with PSReadline 2.1.0 PowerShell 7.3.0-preview.7 with PSReadline 2.2.6 ### Steps to reproduce As per [this issue in the PowerShell Repo](https://github.com/PowerShell/PowerShell/issues/18022) Windows Terminal only allows pasting of a block of text which it then attempts to run line by line no matter how you try pasting as neither CTRL + V, CTRL + SHIFT + V, SHIFT + INSERT or right click paste worked for me ### Expected Behavior One of these pasting methods should paste this as a single block which can then be run by the user as a whole block, not breaking user experience expectations ### Actual Behavior Windows terminal pastes in each line one by one whilst attempting to run individual lines from the pasted text This wrongly creates in PowerShell a Parser error, due to the lack of ability to paste all as a single block before running it as a whole block
claunia added the Issue-QuestionNeeds-TriageNeeds-Tag-FixResolution-Answered labels 2026-01-31 06:12:17 +00:00
Author
Owner

@lhecker commented on GitHub (Sep 5, 2022):

When PowerShell recognizes a Ctrl+V keypress it'll do a block-paste the way you want it, whereas the alternative right-click continues to seemingly paste text line by line. But Windows Terminal binds Ctrl+V to the "paste" action by default already, which prevents PowerShell from adding its custom behavior. It basically won't see the Ctrl+V - all it will see is some incoming text.

You can restore PowerShell's old behavior by simply unbinding Ctrl+V in Windows Terminal. Either remove the

{
    "command": "paste",
    "keys": "ctrl+v"
},

from your settings.json, or remove it in the settings UI here:

image

@lhecker commented on GitHub (Sep 5, 2022): When PowerShell recognizes a Ctrl+V keypress it'll do a block-paste the way you want it, whereas the alternative right-click continues to seemingly paste text line by line. But Windows Terminal binds Ctrl+V to the "paste" action by default already, which prevents PowerShell from adding its custom behavior. It basically won't see the Ctrl+V - all it will see is some incoming text. You can restore PowerShell's old behavior by simply unbinding Ctrl+V in Windows Terminal. Either remove the ```json { "command": "paste", "keys": "ctrl+v" }, ``` from your `settings.json`, or remove it in the settings UI here: ![image](https://user-images.githubusercontent.com/2256941/188441141-a66bd8ae-82f9-4672-9a5d-ecd2af19e6d2.png)
Author
Owner

@kilasuit commented on GitHub (Sep 6, 2022):

@zadjii-msft whilst this does resolve the issue, we should also ensure that documentation is updated to equate for this use case

@kilasuit commented on GitHub (Sep 6, 2022): @zadjii-msft whilst this does resolve the issue, we should also ensure that documentation is updated to equate for this use case
Author
Owner

@ev-dev commented on GitHub (Sep 15, 2022):

Wow thank you so much @lhecker for that quicktip!

I have been wanting to figure out how to paste multiline codeblocks (usually copied from my editor) for a long time but I never knew which part of the tooling stack to make such a change between PowerShell/PSReadLine/Terminal, and I didn't investigate much.

Since I've only ever used PowerShell from within MS Terminal, I had no idea this behavior existed as a default in PowerShell! I'd definitely recommend including a sentence about this specific unbinding somewhere in the docs as the OP mentioned.

@ev-dev commented on GitHub (Sep 15, 2022): Wow thank you so much @lhecker for that quicktip! I have been wanting to figure out how to paste multiline codeblocks (usually copied from my editor) for a long time but I never knew which part of the tooling stack to make such a change between PowerShell/PSReadLine/Terminal, and I didn't investigate much. Since I've only ever used PowerShell from within MS Terminal, I had no idea this behavior existed as a default in PowerShell! I'd definitely recommend including a sentence about this specific unbinding somewhere in the docs as the OP mentioned.
Author
Owner

@ev-dev commented on GitHub (Sep 15, 2022):

The only thing I still wish I could figure out is how to copy/paste a multiline snippet with the indenting removed. Anyone have any ideas on how/where to customize something like that?

Often when I copy a small codeblock from my editor to run in powershell, it is nested somewhere in the actual code in the editor, and so the copied text includes several indents (spaces) on each line. It's likely something better addressed by the editor during the copy (like a VSCode extension? couldn't find one that does this specifically) but I thought I'd ask here and maybe I'll get lucky.

@ev-dev commented on GitHub (Sep 15, 2022): The only thing I still wish I could figure out is how to copy/paste a multiline snippet with the indenting removed. Anyone have any ideas on how/where to customize something like that? Often when I copy a small codeblock from my editor to run in powershell, it is nested somewhere in the actual code in the editor, and so the copied text includes several indents (spaces) on each line. It's likely something better addressed by the editor during the copy (like a VSCode extension? couldn't find one that does this specifically) but I thought I'd ask here and maybe I'll get lucky.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#18383