Independent writing tools and guides, edited by a human

Remove Extra Spaces

Collapse multiple spaces, convert tabs, trim lines, and remove empty lines. Fixes the copy-paste damage word processors hide.

Your workbench
0 characters
Read-only
Ready when you are.
On this page (08)
  1. 01Four problems that arrive together
  2. 02What it changes and what it leaves alone
  3. 03The spaces that are not the space you pressed
  4. 04Why trailing whitespace is the one that bites
  5. 05What you should not clean
  6. 06Cleaning a real paste
  7. 07Frequently Asked Questions
  8. 08Clean the paste, then leave the prose alone

Four problems that arrive together

A paragraph with spacing damage almost never has only one kind. Paste a client's email into your draft and you inherit runs of spaces where someone leaned on the space bar, tabs where a table used to be, and trailing whitespace on every line. Four blank lines sit where a single paragraph break belongs.

They travel together because they come from the same places. Word processors store alignment as tabs, PDF copy leaves a stray space where the page wrapped, and every content management system pastes in whatever its editor produced. Fixing these by hand is possible, and tedious.

What it changes and what it leaves alone

The transformation runs in three steps.

Runs of spaces, tabs, and non-breaking spaces collapse to one ordinary space. Then every line is trimmed, so whitespace before the first visible character and after the last one goes. Then the whole text is trimmed. If you tick the single checkbox, lines containing nothing are deleted.

Nothing else happens. Characters inside words are untouched. A sentence a PDF split across two lines stays split, because joining lines requires deciding which breaks are real paragraph endings, and that decision needs a pattern. The find and replace tool belongs there.

One quiet side effect: a Windows file with \r\n endings comes out with plain \n endings, because the carriage return counts as trailing whitespace. Text from a classic Mac, ending in bare \r characters with no \n, is never split into lines at all, so it arrives as one very long line.

The spaces that are not the space you pressed

The collapse covers three characters: the ordinary space from the space bar, the tab, and the non-breaking space. Everything else stays.

CharacterWhat it isCollapsed mid-lineRemoved at line edges
Space, U+0020What the space bar producesYesYes
Tab, U+0009Alignment character from editors and exportsYes, becomes one spaceYes
Non-breaking space, U+00A0Space that will not break across a lineYes, becomes a normal spaceYes
En space, U+2002Typographic space, half an emNoYes
Em space, U+2003Typographic space, one em wideNoYes
Thin space, U+2009Narrow typographic spaceNoYes
Ideographic space, U+3000Full-width space from CJK inputNoYes
Zero-width space, U+200BInvisible character, not whitespaceNoNo
Soft hyphen, U+00ADInvisible break hint left by PDFsNoNo

The last two rows surprise people. A zero-width space is not whitespace as far as a browser is concerned, so no amount of trimming removes it, and your text keeps a character you cannot see that will defeat a search for the word hiding it. Soft hyphens behave the same way, and the text cleaner is what removes them.

Why trailing whitespace is the one that bites

In prose, a space at the end of a line is invisible and harmless. In three other places it is neither.

In code and data, it makes every diff noisy. A file where one editor stripped trailing spaces on save and another did not will show every line as changed, and version control has no setting for this that a whole team agrees on.

In Markdown, two trailing spaces are meaningful. They are the syntax for a hard line break. Strip them and two lines join into a single paragraph when rendered. The fix is a backslash at the end of the line, which Markdown also accepts as a hard break, or a blank line if you wanted a new paragraph anyway. Our guide to writing Markdown as a writer covers the substitution.

In CSV and tab-separated files, a trailing space changes the value. Smith is not Smith to a database. A join that should match fails, a lookup returns nothing, and the difference is invisible in every spreadsheet view.

What you should not clean

Poetry indented to show its line structure, and plain-text tables aligned with spaces for a human reader, both depend on whitespace this tool deliberately removes.

Cleaning a real paste

Say you copied a two-column conference programme out of a PDF. What you have is one line per visual row, an odd number of spaces in the middle of each, a hard break at every wrap, and six spaces of indentation on the session headings. Some names contain non-breaking spaces.

Run the tool with "Also remove empty lines" ticked and you get one line per visual row, no indentation, no interior runs of spaces, no stray blank lines. What you do not get is a table, because a table needs a delimiter. One more pass through find and replace, matching two or more spaces and replacing with a comma, and a spreadsheet will accept the result.

Then check for duplicates. Two lines that look identical can differ by a trailing space, which is why the duplicate line remover offers a "Compare trimmed lines" option rather than assuming exact matches.

Frequently Asked Questions

Why does my text still look wrong after cleaning?

Because the gaps that remain are usually not spaces. A zero-width space, a soft hyphen, or an em space all survive this tool by design and still render as blank areas. Inspect the suspicious gap somewhere, and if you find an invisible character, the text cleaner removes it.

Does it rejoin lines that a PDF wrapped mid-sentence?

No. Doing that would need a rule about which breaks are paragraph endings and which are page furniture. Use find and replace in regular expression mode, with a pattern that matches a single line break and replaces it with a space, leaving the double breaks alone.

Should I tick "Also remove empty lines"?

Only when a blank line is clutter. It deletes every blank line, including the single one that separates paragraphs in plain text and in Markdown, so ticking it on a manuscript collapses the document into one wall of text. Use it on lists and exported logs.

Will this fix the double space after a full stop?

Yes, and whether you want that is a matter of house style. The tool has no opinion; it collapses every run of spaces wherever it appears. If your publisher still uses the older wide-spacing convention between sentences, this removes it silently.

Do tabs become spaces or disappear?

They become a single space. A tab that separated two columns in a log file turns into a space, which changes the format if anything downstream expects tab-separated input. Convert to a delimited format first.

Clean the paste, then leave the prose alone

Reach for this tool at the boundary rather than in the middle: when a paste lands in your document, and when an export leaves for another system. If spacing turns out to be only half the problem, start with the text cleaner, which removes the invisible characters this tool ignores.