Indent Converter (Tabs ↔ Spaces)
Convert leading indentation between tabs and spaces.
Overview
Convert the leading indentation of every line in your text between tab characters and spaces. Choose tabs-to-spaces or spaces-to-tabs, set the tab width (typically 2, 4, or 8), and the rest of each line is preserved exactly. Trailing and interior whitespace is left alone.
Developers cleaning up source files, technical writers normalizing code blocks for publication, and teams unifying style across a polyglot repo reach for this tool. It's particularly useful when pasting code from a source that uses one convention into a project that uses another.
How it works
The converter inspects only the leading whitespace of each line. In tabs-to-spaces mode, every tab is replaced with N spaces (where N is your chosen tab width), with each tab respecting the next tab stop rather than always emitting the full width. In spaces-to-tabs mode, runs of leading spaces are grouped into N-space chunks and each chunk becomes a single tab; leftover spaces stay as spaces. Interior whitespace (inside string literals, inside comments) is never touched.
Examples
Input (tabs, tab=4):
→print("hello")
Output (spaces):
print("hello")
Input (8 spaces, tab=4):
if (x):
Output (tabs):
→→if (x):
Input (mixed: 6 spaces, tab=4):
indented
Output (tabs):
→ indented ← 1 tab + 2 leftover spaces
FAQ
Why only leading whitespace?
Tabs and spaces inside string literals, comments, or aligned-text columns serve a different purpose. Converting them blindly breaks formatting.
Which tab width should I pick?
Match your project's style guide. Python and JavaScript projects commonly use 4 or 2 spaces; Go projects use tabs and let the renderer pick a width; Makefiles must use tabs.
Will this break my Python code?
PEP 8 forbids mixing tabs and spaces. As long as you convert your whole file to one style consistently, Python will run fine.