Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 887
honzajscz Avatar asked Nov 23 '25 14:11

honzajscz


2 Answers

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

like image 106
honzajscz Avatar answered Nov 27 '25 13:11

honzajscz


@honzajscz's solution is still correct in spirit, however the structure of the Windows Terminal settings.json file has changed since 2021.

Commenting out the line "keys": "ctrl+v" as shown below worked for me. This is still accurate as of 2025-11-25, for Windows Terminal production branch, version 1.23.12811.0.

screenshot of the relevant section of settings.json

Here is some PowerShell which will perform the necessary modification to your settings.json file. This is useful for me because I'm often launching Windows Terminal on freshly reimaged test VMs and sometimes want to paste multiline code without having to manually perform the JSON modification every time.

# The settings.json path may need to be modified for different versions of Windows Terminal (specifically for the Preview branch)
$path = "$($env:LocalAppData)\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json"
# Grab the content of the settings.json file
$content = Get-Content $path | Out-String
# Insert commenting characters before the target line
$target = '"keys": "ctrl+v"'
$replacement = "//$target"
$newContent = $content.Replace($target, $replacement)
# Overwrite the settings.json file with the modified content
$newContent | Set-Content $path
like image 29
mmseng Avatar answered Nov 27 '25 13:11

mmseng



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!