2

I'd like to unwrap lines so that I can turn them from lines with hard line-breaks to no line breaks.

Specifically, this means that contiguous runs of lines with non-whitespace should be joined together Essentially, any \n with no whitespace on either side should be replaced with a single space. Other linebreaks shouldn't get touched.

I feel like it ought to be a search-and-replace with a search string something like (?!\n)\n(?!\n) -> , but that doesn't work, as it doesn't match anything.

Is there an ST2 built-in command for this?

Fueled By Coffee
  • 2,467
  • 7
  • 29
  • 43
Alex Feinman
  • 5,393
  • 1
  • 30
  • 48
  • 2
    i always do cmd+opt q for that, ithink its like join lines in the edit menu. definitely a built-in. – flow Oct 14 '13 at 01:25
  • I did something like this once before by turning all newlines into spaces, and then changing all double spaces back into newlines. Of course, that only works if you know that there aren't any currently-existing double spaces in your text (something that would be easy to find out). – MattDMo Oct 14 '13 at 01:59

3 Answers3

3

any \n with no whitespace on either side

(?<!\s)\n(?!\s)

other linebreaks shouldn't get touched.

(?<!(?:\s|\n))\n(?!\s)

Replace with ''

Lodewijk Bogaards
  • 19,777
  • 3
  • 28
  • 52
2

As @flow mentioned, there are built-ins for that task. Just select the lines you want to join and press Ctrl + J.

And your way should works too. Only you missed a bit. It should be (?<!\n)\n(?!\n)

Kabie
  • 10,489
  • 1
  • 38
  • 45
  • Join, unfortunately, squashes out *all* linebreaks, making my text one long paragraph. – Alex Feinman Oct 15 '13 at 16:55
  • Use multiple selections: select each paragraph, missing out the last line if you don't want blank lines between paragraphs removed. Then you can use Join Lines, or if you want some other separator, Split Into Lines then press End and Del. – deltab Oct 22 '13 at 16:33
0

The following solution works best for text copied from a console log with 80 columns. It only removes \n if the line touches the last column.

Find:

(.{80})\n

Replace:

$1

MrMattSim
  • 151
  • 1
  • 5