23

Is it possible to copy multiple lines from the Windows Command Prompt without it inserting a new line where each line reaches the end of the terminal?

For example, if I have the following line in the console:

c:\very_long_path_here\more_path_here>command_i_want_to_copy -with -some
arguments that wrap over lines.

If I select this and copy it, I will get a newline after the word 'some', which I'll have to delete manually.

Is there a way to copy the data (command that will be parsed, output that is printed) in the form it is interpreted/printed, rather than with hard-wrapped lines?

3
  • 1
    In Win 7/8 there is a clip.exe, which redirects input to clipboard. You can use it like c:\> echo your -command | clip.exe. But it's more suitable for a command output..
    – week
    Mar 15, 2013 at 10:37
  • afaik there is no built in way to do this. but maybe you can combine something like a short autoit script with clip.exe to archive your goal
    – weberik
    Mar 15, 2013 at 12:41
  • 1
    since windows 10 the default behavior will wrap the line selection so no more problem
    – phuclv
    Jan 11, 2016 at 6:53

5 Answers 5

19

The Windows Command Prompt is notoriously broken in this aspect. It is not possible to get the Linux Terminal behavior (at least for pre-Windows 10 according to Luu's comment).

However, there is an obscure feature in cmd.exe which helps: Holding down shift when right clicking into the selected area (to copy) will remove ALL newlines in the copied text.

If you want to select a single long command line (spanning multiple terminal lines) this does what you want. However, it will always remove all newlines, so it is not possible to select multiple command lines (or a script) in a sensible way.

Detailled procedure:

  • Select long command line using the left mouse button
  • Press down shift
  • Right click into the selected area (to copy)
  • Release shift
  • Now the selected text is in the copy buffer without newlines and you can for example paste it into cmd.exe again using the right mouse button
6
  • Interesting, I'd never heard of that feature. It looks like that's as good as it's going to get. I don't use windows anymore, but when I get the chance to confirm it I'll accept this answer. :-) Oct 9, 2015 at 2:32
  • 1
    since windows 10 you'll get Linux behavior by default
    – phuclv
    Feb 20, 2016 at 3:09
  • ... so "It is not possible to get the Linux Terminal behavior" is incorrect
    – phuclv
    Feb 23, 2016 at 7:08
  • @Luu: Thanks for adding the info about Windows 10. But what do you mean with 'by default'? This suggests that there is an alternative behavior for pre-Windows 10 systems, which there isn't, so your comment is misleading. Also: Who is using Windows 10? (SCNR) Feb 25, 2016 at 13:59
  • 1
    I use Windows 10 and it works when copying output of commands but not when copying statements from the command prompt. Example: 1) Type a command that spans multiple lines in command promp; 2) copy it - the unwanted NewLines will go to the clipboard as well). Jan 24, 2017 at 14:25
4

Another option is to open the context menu of the console window's title bar, go to Properties and make the screen buffer's width large enough that things don't wrap. (9999 appears to be the maximum value.)

If you're having to do this a lot, you can change the option in Defaults instead of Properties.

Of course, this method breaks down if the lines are longer than 9999 characters.

2
  • 1
    Nice idea, too! Less obscure to use, but less visibility. Feb 25, 2016 at 14:01
  • 1
    @Abraxas I've rewritten the answer in much more detail.
    – 1j01
    Mar 4, 2016 at 5:21
1

To enable this for Windows 10:

With either a "cmd" or "Windows Powershell" window, navigate to properties (click icon in upper left) and select the option "Enable line wrapping selection".

My Powershell prompt did not have this enabled, enabling it did the trick for me.

1
  • I cannot find this option in Windows Terminal 1.8.1444.0 - do you know if there's a json setting? May 28, 2021 at 0:00
-2

Just copy the code into notepad then in the menu bar,click Format then click Word Wrap

-4

Use the SET and then combine the parts in the expression. Additionally you can do for such purposes batch file or macro.

@set WAIKTools=%ProgramFiles%\WAIK\Tools\amd64
@set LabelCD=GRTMPVOL_RU

@IF "%time:~0,1%" GTR "0" SET current=%DATE:~-4%-%DATE:~3,2%-%DATE:~0,2%@%TIME:~0,2%.%TIME:~3,2%.%TIME:~6,2%
@IF "%time:~0,1%" LSS "0" SET current=%DATE:~-4%-%DATE:~3,2%-%DATE:~0,2%@0%TIME:~1,1%.%TIME:~3,2%.%TIME:~6,2%

"%WAIKTools%\oscdimg.exe" -h -m -n -l%LabelCD% -b"%cd%\boot\w32sp3.bif" "BUILD-%current%" "BUILD-%current%-ISO\%LabelCD%.ISO"
1
  • 2
    This answer has nothing to do with the question. Where is the copy part? Where is the Windows terminal part? Apr 20, 2016 at 22:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.