26

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?

6 Answers6

20

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
Johannes Overmann
  • 911
  • 3
  • 9
  • 19
5

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.

1j01
  • 202
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.

0

The following has finally worked for me in Windows 10:

  • Enter the selection mode via system menu (Edit->Mark)
  • Click and hold left Alt
  • While holding it select your text lines with mouse
  • Right click to copy
  • Paste - enjoy!
-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"
STTR
  • 6,891