Convert leading spaces to tab characters for code that requires tab indentation. Set your space width (2, 4, or 8), convert only leading indentation or all spaces, and see a live whitespace visualiser showing every tab and space.
Paste code or text that uses spaces for indentation. The tool works with any indentation depth — 2-space, 4-space, or 8-space styles. Mixed indentation is handled gracefully.
Choose how many spaces equal one tab: 2, 4, or 8 (matching your project standard). The tool groups consecutive leading spaces by your tab width and replaces each group with a single tab character. Remainder spaces are left as spaces.
The output appears instantly. Enable the whitespace visualiser to see tabs as → and spaces as · to verify the conversion is correct. Copy to clipboard or download the converted file.
Some languages and projects require tab-based indentation. Go (Golang) uses tabs as the official style enforced by gofmt. Makefiles require tab characters (not spaces) before recipe lines — a space will cause "missing separator" errors. Converting a space-indented file to tabs can also reduce file size since one tab character replaces up to 8 space characters.
Yes. If your tab width is 4 and a line starts with 9 spaces, the tool produces 2 tabs and 1 space — 2 complete tab-widths (8 spaces) are converted to 2 tabs, and the remaining 1 space stays as a space. This prevents misalignment in deeply nested code.
Leading spaces only converts only the spaces at the very start of each line — the indentation. Spaces within the line content are left untouched. This is the safe mode for code. All spaces converts every space character in the entire text to a tab, useful for converting TSV-style space-delimited data.
Python 3 disallows mixing tabs and spaces for indentation. If you convert all leading spaces to tabs consistently with the correct tab width, the code remains valid. Always test Python files after conversion and consider using Black for production Python indentation.
The shell command unexpand -t 4 converts leading spaces to tabs. This tool does the same without requiring a terminal, handles Windows CRLF line endings correctly, and provides visual confirmation via the whitespace visualiser — ideal for quick one-off conversions.
The tool preserves your line endings. Files with Windows-style CRLF line endings maintain CRLF; Unix LF files maintain LF. You can also choose to normalise line endings to LF using the line ending option.