Spaces to tabs, plain and predictable
Spaces to tabs conversion replaces runs of spaces (and optionally other whitespace) with tab characters. The behaviour depends on the Mode control. Fixed Width, the default, replaces every run of exactly tab_width spaces with a single tab; runs of a different length are left as-is. Repeated Spaces replaces every run of two or more spaces with a single tab, regardless of length. All Whitespace replaces every individual space or tab with a tab character. Repeated Whitespace replaces every run of two or more spaces or tabs with a single tab.
Fixed Width is the right choice for re-tabifying source code that was previously expanded with a known width. Repeated Spaces is the right choice when the original spacing was inconsistent (mixed two and four-space indents) and you want to collapse every multi-space gap into a tab. All Whitespace and Repeated Whitespace are useful for converting visually aligned text into tab-separated values for a downstream parser. Each mode is a flat regex replace, not column-aware.
The Tab width control is only used by Fixed Width mode. It accepts integer values from 1 to 16 with a default of 4. Other modes ignore the value. Newlines and other non-space, non-tab characters pass through untouched in every mode. For the inverse direction, see tabs to spaces.
How to use convert spaces to tabs
- 1Paste your space-indented text into the input panel on the left.
- 2Pick a Mode: Fixed Width, Repeated Spaces, All Whitespace, or Repeated Whitespace.
- 3For Fixed Width, set Tab width to the number of spaces that should collapse to one tab.
- 4The retabbed text appears in the output panel on the right as you type.
- 5Click Copy in the output header to copy the result.
Keyboard shortcuts
Drive TextResult without touching the mouse.
| Shortcut | Action |
|---|---|
| Ctrl F | Open the find & replace panel inside the input Plus |
| Ctrl Z | Undo the last input change |
| Ctrl Shift Z | Redo |
| Ctrl Shift Enter | Toggle fullscreen focus on the editor Plus |
| Esc | Close find & replace, or exit fullscreen |
| Ctrl K | Open the command palette to jump to any tool Plus |
| Ctrl S | Save current workflow draft Plus |
| Ctrl P | Run a saved workflow Plus |
What this tool actually does
Mode: Fixed Width
The default. Every run of exactly tab_width consecutive spaces collapses to a single tab. Runs of a different length pass through unchanged. So with width 4, four spaces becomes \t, eight becomes \t\t, three or five stay as spaces. Use this when re-tabifying code that was previously expanded with a known width.
Mode: Repeated Spaces
Every run of two or more consecutive spaces collapses to a single tab, regardless of length. So two, three, four or twenty spaces all become a single \t. Single spaces pass through unchanged. Tabs in the source pass through unchanged. Use this when the source has inconsistent indent widths and you want a single tab per gap.
Mode: All Whitespace
Every individual space or tab character is replaced with a tab. Newlines pass through untouched. The result has no spaces left at all, only tabs and newlines. Use this when converting visually aligned columns into tab-separated values for a downstream parser that expects strict \t delimiters.
Mode: Repeated Whitespace
Every run of two or more consecutive spaces or tabs collapses to a single tab. Single spaces and single tabs pass through unchanged. Use this when the source mixes spaces and tabs and you want every multi-character gap to become exactly one tab.
Runs entirely in your browser
No upload, no server-side processing, no log of what you pasted. The replace runs on every keystroke via a single regex pass per mode. Long files of a few hundred kilobytes still convert in under a second on a desktop browser.
Worked example
Fixed Width mode with tab width 4. Each four-space run collapses to a single tab; other characters pass through.
name email role Alice [email protected] admin
name email role Alice [email protected] admin
Settings reference
| Setting or rule | Effect on output |
|---|---|
| Mode: Fixed Width (default) | Run of exactly tab_width spaces collapses to one tab. Other run lengths untouched. |
| Mode: Repeated Spaces | Run of two or more spaces collapses to one tab, regardless of length. |
| Mode: All Whitespace | Every individual space or tab is replaced with a tab. |
| Mode: Repeated Whitespace | Run of two or more spaces or tabs collapses to one tab. |
| Tab width (default 4) | Number of spaces that count as one tab in Fixed Width mode. Other modes ignore this value. |
| Newlines | Pass through untouched in every mode. |
| Other characters | Pass through untouched in every mode. |