Tabs and extra indentation sneak into text from copied documents, spreadsheets, and code. Here is how to remove them cleanly.
Tabs vs spaces
A tab is a single character that renders as a variable-width gap. Text copied from spreadsheets, tables, and some documents is full of them, and they behave differently from spaces, so they cause misalignment when you paste elsewhere.
Method 1: find and replace
In any editor:
- To convert tabs to spaces, search for the tab character (
\tin a regex-capable editor) and replace with a space or two. - To remove tabs entirely, replace
\twith nothing. - To strip leading indentation from every line, search for
^\s+and replace with nothing (this removes leading tabs and spaces).
Method 2: a cleaner
Paste the text into a cleaner that normalizes whitespace. textscrubr collapses runs of spaces, trims trailing whitespace, and, when you flatten formatting, removes leading indentation, giving you flush, even lines. It also strips the invisible characters and normalizes exotic spaces that copied text usually brings along.
Be careful with code
In code, indentation is meaningful, and in some languages (like Python) it is part of the syntax. Removing tabs or leading spaces from code will break it. If you are cleaning code, either leave the indentation alone or convert tabs to spaces consistently rather than deleting them. A structure-aware cleaner leaves code spacing untouched by default and only tidies prose.
Converting tabs to spaces consistently
If your goal is consistency rather than removal (common in code), most editors have a "convert indentation to spaces" command that replaces tabs with a fixed number of spaces throughout. That keeps the structure while making the whitespace uniform.
Quick recap
For prose, remove stray tabs and extra indentation freely. For code, convert tabs to spaces consistently instead of deleting them, or use a cleaner that leaves code spacing intact.