How to Remove Extra Spaces in VS Code and Sublime Text
Code and text files pick up extra spaces the same way any pasted text does: copied from a webpage or a PDF, pasted from log output, or left behind by mixed indentation. VS Code and Sublime Text both fix it with Find and Replace, using the same search patterns.
Open Find and Replace with regex on
Open Find and Replace, then turn on pattern matching. In both editors this is a small .* icon inside the Find and Replace panel; leave it off and every pattern below is matched as plain text and finds nothing.
Skip the manual steps. Clean your text instantly, right here.
Clean it instantly with the free toolReplace two or more spaces with one
Remove blank lines
Both editors treat ^ and $ as the start and end of every line by default
in this mode, so this pattern needs no extra setting to work across the whole file.
Trim spaces at the start or end of every line
Cleaning just part of a file
VS Code has a "Find in Selection" toggle in the Find panel: highlight a block first, turn it on, and Replace All only touches the highlighted text. Sublime Text's Replace All always runs on the whole open file, so for a partial cleanup there, copying the block into the free tool and pasting the result back is faster than working around it.
For text that isn't already saved in a file, or a one-off cleanup where opening an editor is more setup than the job is worth, the free tool does all three of the above in one paste.