Text copied from documents, PDFs, and chatbots often arrives with big vertical gaps, multiple blank lines stacked between paragraphs. Here is how to tidy them.
What causes extra blank lines
Sources add vertical spacing in different ways. When you copy and paste, those extra line breaks come along, so you end up with two, three, or more blank lines where one would do. It makes the text look sparse and unprofessional and wastes space.
Method 1: a cleaner
The easiest fix is a cleaner that collapses runaway blank lines automatically. textscrubr reduces any run of three or more line breaks to a single blank line between paragraphs, trims blank lines at the very start and end, and removes trailing whitespace, all while keeping your real paragraph breaks and structure.
Method 2: find and replace with regex
In a regex-capable editor:
- Search for
\n{3,}(three or more consecutive line breaks). - Replace with
\n\n(a single blank line).
This leaves exactly one blank line between paragraphs. If your editor uses a different newline representation, you may need to enable regex mode or adjust the pattern, but the idea is the same: collapse runs of blank lines down to one.
Keep one break between paragraphs
The goal is not to remove all blank lines, it is to keep a single, consistent break between paragraphs. A single blank line separates paragraphs cleanly in most contexts, including Markdown, where a blank line is what actually creates a new paragraph. Removing every blank line would merge your paragraphs into one block.
Watch code blocks
Inside code, blank lines can be intentional. A structure-aware cleaner leaves code spacing alone and only collapses blank lines in ordinary prose, so you tidy the document without disturbing code samples.
Quick recap
Collapse runs of three or more line breaks to one, keep a single break between paragraphs, and leave code alone. A cleaner does all three at once.