Spaces to Tabs

Convert leading indent spaces into tabs using a tab size you choose.

What Spaces to Tabs helps you do

Convert leading indentation spaces into tab characters using a tab size you set. This is the reverse conversion for switching a space-indented file to tabs while keeping the visual indentation the same. Only the spaces at the start of each line are converted; spaces inside the line are left alone.

The conversion is local to your browser. Nothing is uploaded to Haivix.

How it works

Each cleanup tool applies one deterministic string transformation to the pasted text inside the page. There is no parser, model or server call: the same input and options produce the same output every time. The browser holds the text in memory, so the result updates as you edit and is not retained after the tab closes. Because the transformation is literal, non-breaking spaces, mixed line endings and tabs may behave differently from a word processor; compare a short sample before applying it to a large file. The page never rewrites the source on disk, so the only undo is your own copy.

How to use Spaces to Tabs

  1. Paste the space-indented text.
  2. Set the tab size so it matches the existing indentation.
  3. Convert and check the leading whitespace in a tab-aware editor.
  4. Copy the tab-indented result.

When to use it

  • Convert a space-indented file to tabs for a repository that requires them.
  • Shrink indentation characters for a file-size-sensitive context.
  • Match a project that enforces hard tabs.
  • Normalize a pasted code block before comparing it with a tab-indented source.
  • Convert leading indentation in a configuration excerpt.
  • Prepare a snippet for an editor that displays tabs at a specific width.

When not to use it

  • Do not use it on prose; the conversion is for leading indentation.
  • Do not use it when internal alignment spaces must be preserved exactly.
  • Do not use it on a file whose indentation is not a multiple of the tab size.

Example

A line indented with four spaces becomes one tab when the tab size is four. A line with six leading spaces becomes one tab and two spaces, so the visual column is preserved. Two spaces of alignment inside a line are not touched.

What you can do with Spaces to Tabs

  • Convert leading spaces to tabs at 1–16 spaces per tab.
  • Leave internal spaces and alignment untouched.
  • Keep lines that are already tab-indented.
  • Preserve the visual indentation in a tab-aware editor.
  • Copy the tab-indented result.
  • Run the conversion locally with no upload.

Example: verify the cleanup on a sample

Paste a short, representative sample first rather than the whole file. Check the edges: leading and trailing spaces, blank lines, tabs and any non-breaking spaces the source may contain.

Apply the transformation and compare the sample with the original. If the change is correct, run the full text; if not, adjust the source or choose a different cleanup tool.

Copy or download the result and keep the original until the destination import succeeds. Most of these tools are one-way, so the source file is the only reliable undo.

If the text came from a PDF, a spreadsheet or a CMS, look for invisible characters before blaming the cleanup. A no-break space or a soft hyphen can survive the pass and still break a comparison downstream.

Run the cleaned text through the destination's preview or import step before deleting anything. A formatting change that looks right in the textarea can still fail a strict parser.

What to know before you start

  • Only leading indent spaces are converted, so internal alignment is left alone.
  • Indentation not divisible by the tab size may not convert cleanly.
  • The visual result depends on the tab width in the destination editor.
  • There is no option to convert internal spaces.

Common mistakes

  • Choosing a tab size different from the source editor, which shifts indentation.
  • Expecting internal alignment spaces to convert.
  • Applying it to text where indentation is not a multiple of the tab size.
  • Using it on prose and changing the first word's position.
  • Forgetting that the destination editor may display tabs at a different width.

Troubleshooting

If indentation looks wrong, the tab size does not match the source; restore the original and try the other common size.

If some lines did not convert, their leading whitespace is not a multiple of the tab size.

If internal columns moved, the line used leading spaces for alignment; keep the original.

If the result looks unchanged, the source may already use tabs.

Related standards and documentation

  • Unicode whitespace includes characters such as the no-break space that may not look like a space.
  • Line endings may be CRLF, LF or CR before cleanup; normalize them first when the target requires one style.
  • The tools operate on Unicode text, not on bytes in a legacy encoding.
One transformation, checked on a sample
  • Compare a short sample first.
  • Watch for non-breaking spaces and tabs.
  • Keep the original until the import works.

Frequently Asked Questions