Convert spaces to tabs

Paste any space-indented text and get the same text with runs of spaces collapsed back into tab characters. The spaces to tabs converter offers four modes: fixed-width replacement, repeated spaces, all whitespace, and repeated whitespace. The Tab width control sets how many spaces count as one tab in fixed mode. The transform runs in your browser; nothing uploads.

Input
Line 1:1 LF cloud_done Saved locally
Result Spaces to Tabs
0 lines 0 chars

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

  1. 1Paste your space-indented text into the input panel on the left.
  2. 2Pick a Mode: Fixed Width, Repeated Spaces, All Whitespace, or Repeated Whitespace.
  3. 3For Fixed Width, set Tab width to the number of spaces that should collapse to one tab.
  4. 4The retabbed text appears in the output panel on the right as you type.
  5. 5Click Copy in the output header to copy the result.

Keyboard shortcuts

Drive TextResult without touching the mouse.

Shortcut Action
Ctrl FOpen the find & replace panel inside the input Plus
Ctrl ZUndo the last input change
Ctrl Shift ZRedo
Ctrl Shift EnterToggle fullscreen focus on the editor Plus
EscClose find & replace, or exit fullscreen
Ctrl KOpen the command palette to jump to any tool Plus
Ctrl SSave current workflow draft Plus
Ctrl PRun 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.

Input
name    email    role
Alice    [email protected]    admin
Output
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.

FAQ

Which mode should I use for source code?
Fixed Width with the matching tab width is the safest choice. If your editor expanded tabs to four spaces, set the width to 4. If it used eight, set the width to 8. The result re-tabifies indents that were previously expanded with that width and leaves alignment runs of other lengths alone.
What does Repeated Spaces do differently?
Repeated Spaces collapses every run of two or more consecutive spaces into a single tab, regardless of length. That is useful when the source has mixed indent widths (two-space and four-space indents in the same file) and you want every multi-space gap to become one tab. Single spaces are untouched.
When would I use All Whitespace?
All Whitespace replaces every individual space or tab with a tab. Use it when converting visually aligned text into a tab-separated value file. The output has no spaces left at all, only tabs and newlines, which is what most TSV parsers expect.
Is the text sent anywhere?
No. The replace runs entirely in your browser via JavaScript. Nothing is uploaded, nothing is logged, no record of your text exists on our servers.
How do I go the other way?
Paste your tabbed text into tabs to spaces. That tool replaces every tab character with a run of spaces of a configurable width.