TextyConverterbeta
⌘K

Spaces → Tabs

Replace runs of N leading spaces with a tab character. Only the indentation portion of each line is touched.

spaces per tab

About Spaces → Tabs

This tool replaces leading runs of N spaces with a single tab. Only the indentation at the start of each line is converted — spaces inside the line are preserved so prose and code keep their spacing.

When to use it

  • Converting space-indented code to a project that uses tabs
  • Matching the indent convention of an existing codebase
  • Reducing file size when many lines are heavily indented

How it works

For each line, the leading whitespace is matched. Groups of N consecutive spaces in that prefix become a tab; any leftover spaces (less than N) stay as spaces. The rest of the line is left alone.

Examples

8 spaces → 2 tabs; 6 spaces → 1 tab + 2 spaces
    foo
        bar
      baz
(N=4)
	foo
		bar
	  baz

Frequently asked questions

Does it affect spaces inside the line?
No. Only the leading indentation portion is touched. Spaces between words elsewhere on the line are preserved.
What happens to lines with fewer than N leading spaces?
They pass through unchanged — there's nothing to compress into a tab.

Related tools