Cannot Paste blocks of code into Windows Terminal

Welcome Forums General PowerShell Q&A Cannot Paste blocks of code into Windows Terminal

Viewing 13 reply threads
  • Author
    Posts
    • #226002
      Participant
      Topics: 4
      Replies: 6
      Points: 84
      Rank: Member

      Good Morning Everyone,

      My issue comes with how PowerShell is handling when I paste in text.  If I open Powershell directly, it works as expected, allows me to paste in a block of text and execute.  If I paste the same code into Windows Terminal, it wants to run every line individually.  I’ve checked $PSVersionTable, and they are both running the same version of powershell. What am I missing here?

      https://snipboard.io/BCWfiy.jpg – Snaggy Link to a screen shot of the issue

      Thanks,

      -Rob

    • #226041
      Participant
      Topics: 4
      Replies: 2249
      Points: 5,494
      Helping Hand
      Rank: Community MVP

      But that’s the standard behaviour on all consoles except of the ISE. … at least it is this way here on all of my machines … 😉

    • #226044
      Participant
      Topics: 4
      Replies: 6
      Points: 84
      Rank: Member

      I wonder what I’ve changed in the past then that I can’t find now.  Because PowerShell by itself does not have that behavior, it acts like I thought it would, I can paste an entire script in before it starts executing.

    • #226092
      Participant
      Topics: 6
      Replies: 93
      Points: 428
      Helping Hand
      Rank: Contributor

      By windows “terminal” I assume you mean a command shell? That shell is NOT an interactive scripting shell. You will need to enter “powershell” in the command shell first to get the behavior you desire.

       

    • #226095
      Participant
      Topics: 4
      Replies: 2249
      Points: 5,494
      Helping Hand
      Rank: Community MVP

      By windows “terminal” I assume you mean a command shell?

      ….. hhhmmmm … quite … 😉

      https://github.com/Microsoft/Terminal#welcome-to-the-windows-terminal-console-and-command-line-repo

    • #226098
      Participant
      Topics: 6
      Replies: 93
      Points: 428
      Helping Hand
      Rank: Contributor

      Understood, thanks Olaf 🙂

    • #226137
      Participant
      Topics: 4
      Replies: 6
      Points: 84
      Rank: Member

      Olaf is correct, that is the program that I am using.

      Below is a screen shot of what I’m trying to explain.  PowerShell is in blue.  PowerShell in Windows Terminal is in Black, Notepad to the right with the simple write-host block of text.

      As you can see, PowerShell stand alone pastes the entire block of text and then executes, where PowerShell in windows terminal wants to execute every line separately.   In this example it doesn’t really matter, but if I’m pasting in something with 30-50 lines of code, it causes issues.

       

    • #226149
      js
      Participant
      Topics: 29
      Replies: 814
      Points: 2,456
      Helping Hand
      Rank: Community Hero

      Oh I got it. In powershell console, hit control v to paste. But I have psreadline set to emacs mode, so that key gets rebound for me.

      It should work in Windows Terminal too, unless your settings file binds control-v to something else. Psreadline has to control it. It looks like Vscode controls control-v as well.

      • This reply was modified 3 weeks, 6 days ago by js.
      • This reply was modified 3 weeks, 6 days ago by js.
      • This reply was modified 3 weeks, 6 days ago by js.
      • This reply was modified 3 weeks, 6 days ago by js.
      • This reply was modified 3 weeks, 6 days ago by js.
    • #226182
      Participant
      Topics: 6
      Replies: 93
      Points: 428
      Helping Hand
      Rank: Contributor

      OK, I will throw this out there, see where it lands. I have always use the right mouse to paste into a shell, be it powershell or a command shell. Right click in the shell and whatever is in the clipboard is copied. Have you tried that?

    • #226185
      js
      Participant
      Topics: 29
      Replies: 814
      Points: 2,456
      Helping Hand
      Rank: Community Hero

      I already solved it.

    • #226212
      Participant
      Topics: 6
      Replies: 93
      Points: 428
      Helping Hand
      Rank: Contributor

      And you solved it how? What did I miss? BTW, I see no screen shots.

    • #226215
      Participant
      Topics: 4
      Replies: 6
      Points: 84
      Rank: Member

      I don’t see a fix either…
      Tony, in powershell, ctrl-v, shift+insert both paste the text as a block.  If I right click it wants to run line by line.

      In Windows terminal, ctrl-v, shift+insert, and right click all want to run the text line by line.

      • #226227
        js
        Participant
        Topics: 29
        Replies: 814
        Points: 2,456
        Helping Hand
        Rank: Community Hero

        Go into your windows terminal settings, and delete or comment out the binding for control+v.

        • This reply was modified 3 weeks, 5 days ago by js.
        • This reply was modified 3 weeks, 5 days ago by js.
        • This reply was modified 3 weeks, 5 days ago by js.
    • #226431
      js
      Participant
      Topics: 29
      Replies: 814
      Points: 2,456
      Helping Hand
      Rank: Community Hero

      For example. change

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

      to this, to comment it out.

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

      Strange that the settings it comes with isn’t as good as the default settings, and doesn’t have the themes.

      • This reply was modified 3 weeks, 5 days ago by js.
    • #226515
      Participant
      Topics: 4
      Replies: 6
      Points: 84
      Rank: Member

      JS, that worked like a charm.  Thank you.

      For example. change

      <textarea class=”ace_text-input” style=”opacity: 0; height: 17.6px; width: 6.59775px; left: 44px; top: 0px;” spellcheck=”false” wrap=”off”></textarea>

      1
      { “command”: “paste”, “keys”: “ctrl+v” },
      XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

      to this, to comment it out.

      <textarea class=”ace_text-input” style=”opacity: 0; height: 17.6px; width: 6.59775px; left: 44px; top: 0px;” spellcheck=”false” wrap=”off”></textarea>

      1
      // { “command”: “paste”, “keys”: “ctrl+v” },
      XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

      Strange that the settings it comes with isn’t as good as the default settings, and doesn’t have the themes.

Viewing 13 reply threads
  • You must be logged in to reply to this topic.