Overview
Introduction
Pasted code or quoted text often arrives with extra leading indentation that no longer matches its new context.
Manually deleting the same number of leading characters from every line in a text editor is slow and easy to get wrong.
What Is Text Dedenter?
A dedenter that removes up to a chosen number of leading copies of an indent unit from the start of every line in a block of text.
It runs entirely client-side as part of this site's String Tools collection, so nothing you paste is ever uploaded to a server.
How Text Dedenter Works
For each line, the tool repeatedly checks whether the line starts with the indent unit and strips it, up to the chosen number of levels, stopping early on a line as soon as the indent unit no longer matches.
The transformation happens synchronously in JavaScript the moment you type, with no network round trip involved.
When To Use Text Dedenter
Use it to un-nest a block of code that was pasted from one level deeper, strip '> ' quote markers from quoted text, or remove accidental leading whitespace.
It's a fast way to get the answer without opening a code editor, a REPL, or writing a one-off script just to check.
Often used alongside Text Indenter, Left Aligner and Whitespace Remover.
Features
Advantages
- Stops safely on lines with less indentation than requested instead of deleting unrelated content.
- Works with any indent unit, not just spaces.
Limitations
- Requires the indent unit to match exactly at the start of each line; it won't detect and normalize mixed tab/space indentation automatically.
Examples
Best Practices & Notes
Best Practices
- Set the indent unit to '> ' to quickly strip email or chat quote markers from pasted text.
Developer Notes
Each line runs its own bounded loop that strips one copy of `indentUnit` per iteration via `startsWith`/`slice`, breaking as soon as a line no longer starts with the unit, so partially indented lines are handled gracefully rather than throwing.
Text Dedenter Use Cases
- Un-nesting a code snippet pasted one level too deep
- Stripping '> ' quote markers from quoted email or chat text
- Removing accidental leading whitespace copied from a rendered web page
Common Mistakes
- Setting the indent unit to a single space when the original text was actually indented with tabs, which causes nothing to be removed.
Tips
- If you're not sure how many levels to remove, start with a high number; lines that run out of matching indentation are simply left as-is.