Whitespace Cleaner
Normalise the invisible parts of a document: trim leading and trailing spaces, collapse repeated spaces, convert tabs to spaces or back, and standardise line endings to LF or CRLF.
How Whitespace Cleaner works
Paste text with inconsistent spacing.
Pick the normalisation rules to apply.
Use the whitespace visualiser to confirm what changed.
Copy the normalised text.
When to use Whitespace Cleaner
- Removing trailing spaces from every line of a file before you commit it, so a diff does not fill up with invisible changes.
- Standardising a document to LF line endings after it picked up Windows CRLF breaks somewhere along the way.
- Converting tabs to a fixed number of spaces, or leading spaces back to tabs, so indentation is consistent with the destination.
- Collapsing the runs of spaces that appear when text is pasted from a formatted source such as a table or a PDF.
- Replacing non-breaking and other exotic spaces that read like an ordinary space but quietly break search and matching.
- Using the whitespace visualiser to see exactly where the hidden characters are before you decide which rules to apply.
Examples
Input
Heading Item one here
Output
Heading Item one here
Leading and trailing spaces on each line are trimmed, the non-breaking space between “one” and “here” becomes a normal space, and the blank line at the end of the document is removed. Line endings are standardised to LF.
Input
def run(): return 1
Output
def run(): return 1
With Tabs to spaces on and a tab width of two, each tab becomes two spaces, so the indentation matches tools that assume spaces.
Input
One two three
Output
One two three
Collapse repeated spaces reduces any run of two or more spaces or tabs to a single space, without touching the line breaks.
How Whitespace Cleaner works under the hood
Every pass starts by normalising carriage-return and CRLF endings to line feeds, so the rest of the rules only ever deal with one kind of break and the tool behaves the same whatever platform the text came from. The chosen line ending — LF, CRLF, or Keep — is applied right at the end, so if you specifically need Windows breaks back, the output is re-encoded after all the cleaning is done.
The rules run in a deliberate order. Exotic spaces are normalised first, then tab and space conversion, then collapsing, then trimming, then document trimming. Exotic spaces cover the ones that look ordinary but are not — the non-breaking space, the thin, hair, and figure spaces in the U+2000 block, the narrow no-break space, the medium mathematical space, and the ideographic space — all folded to a plain space so search, string comparison, and word wrapping behave predictably.
Tab conversion is directional and precise. Tabs to spaces replaces every tab with your chosen width in spaces. Spaces to tabs only rewrites the leading indentation of each line, grouping runs of leading spaces into tabs by the tab width and leaving any remainder as spaces; spaces that fall between words inside the line are never touched. The two are mutually exclusive — turning one on switches the other off — so you cannot accidentally round-trip the indentation.
Trimming has two levels. Trim line edges strips whitespace from both ends of every line; if that is off but Remove trailing spaces is on, only the end of each line is cleared, which preserves indentation while still removing the invisible spaces after the last visible character. Trim document then removes blank lines at the very start and end of the text. Alongside the output, a report counts what the tool found — trailing- and leading-space lines, tab characters, exotic spaces, repeated spaces, and CRLF endings — and the optional visualiser renders spaces, tabs, exotic spaces, and line breaks as visible marks so you can confirm the change.
Common mistakes
- Leaving the line ending on LF when the destination needs CRLF. LF is right for repositories and Unix tools, but a few older Windows programs expect CRLF — set it explicitly when that is the target.
- Expecting Spaces to tabs to convert every space. It only rewrites leading indentation; spaces between words are intentionally kept, so mid-line spacing is unchanged.
- Assuming Collapse repeated spaces will fix indentation. It squeezes runs of spaces anywhere, including inside a line, so it can flatten alignment you meant to keep — use tab conversion for indentation instead.
- Treating an exotic space as a normal one. A non-breaking or thin space looks identical on screen but is a different character; if search or a comparison keeps failing, normalising exotic spaces is usually the fix.