Double spaces sneak into text from old typing habits, pasted content, and AI output. Here is how to remove them without creating new problems.
The quick way: a cleaner
Paste your text into a tool that collapses spacing and every run of multiple spaces becomes a single space at once. The advantage over manual find-and-replace is that a structure-aware cleaner:
- collapses doubles and longer runs in one pass
- removes trailing spaces at the end of lines
- leaves indentation and code spacing alone, so your nested lists and code blocks do not get flattened
textscrubr does this while also stripping the invisible characters and non-breaking spaces that often cause the odd gaps in the first place.
Find and replace
In any editor:
- Open find-and-replace.
- Search for two spaces (
). - Replace with one space (
). - Run it more than once, because three spaces become one space plus one extra, and you want to catch the leftovers. Repeat until it finds nothing.
If your editor supports regular expressions, search for {2,} and replace with a single space to catch every run at once.
Watch out for indentation and code
Blunt space-collapsing is dangerous in two places:
- Code, where indentation is meaningful and double spaces inside strings may be intentional.
- Nested lists, where leading spaces define the structure.
This is why a structure-aware cleaner is safer than a global find-and-replace: it knows to leave leading indentation and code spacing alone and only collapses the runs inside ordinary prose.
Where double spaces hide
The classic case is two spaces after a period, a holdover from typewriters. But they also appear from pasted web content, merged text, and non-breaking spaces masquerading as regular ones. Normalizing odd spaces first, then collapsing the runs, clears all of it.