1

Is there a way to join lines between new lines (return), and keep the new line (return)? Been doing it with Ctrl+J after selecting the text between the new lines, but not practical with large documents.

Something to transform text from:

Mary had a 
little lamb.
His fleece was 
white as snow, yeah.

And everywhere the child went. That little lamb was sure to go now.

He followed her to school one day. Which broke the teachers cool.

to:

Mary had a little lamb. His fleece was white as snow, yeah.

And everywhere the child went. That little lamb was sure to go now.

He followed her to school one day. Which broke the teachers cool.

phuclv
  • 30,396
  • 15
  • 136
  • 260

2 Answers2

2
  • Press Ctrl+H
  • Find what: (?<!\r\n)\r\n(?!\r\n)
  • Replace with: nothing (empty string)
  • Search mode: Regular Expression

Then replace all

(?<!\r\n) and (?!\r\n) are regex lookarounds to make sure that you match exactly only 1 new line. If the file is in Unix format then just remove \r


If you also want to put spaces after punctuation then use this

  • Press Ctrl+H
  • Find what: ([[:punct:]])(?=\R\S)
  • Replace with: \1 (with a space at the end)
  • Search mode: Regular Expression
  • Replace All, then do the (?<!\r\n)\r\n(?!\r\n) replacement above
phuclv
  • 30,396
  • 15
  • 136
  • 260
0
  • Press CTRL+H
  • Find what: (.+)\R(.+)\R(.+)\R(.+\R?)
  • Replace with: $1$2$3$4
  • Search mode: Regular Expression
  • Click Replace All

Before

Input before clicking Replace All

After

Output after clicking Replace All