# Text tabs to spaces

`text-tabs-to-spaces` · version 1.0.0 · Text · free, no key needed

Convert tab characters to spaces.

**Use when you need to: text tabs to spaces · convert tabs to spaces · replace tabs with spaces.**

## Supported

- text tabs to spaces
- convert tabs to spaces
- replace tabs with spaces

## Not supported

- convert spaces to tabs
- unicode width alignment
- read files

## Behavior

- Replaces tab characters (\t) with space characters.
- Lines are recognized across standard line endings: LF (\n), CRLF (\r\n), and CR-only (\r).
- If leading_only is true, only tabs in leading whitespace (before the first non-whitespace character) on each line (including after LF, CRLF, or CR) are replaced.
- If leading_only is false or omitted, all tab characters throughout the text are replaced.
- Each replaced tab is converted to exactly tab_width spaces (between 1 and 16, default 4).
- Does not calculate visual tab stops or Unicode character widths.
- Returns the modified text and the number of tabs replaced.

## Input

- `text` (string, required): max length 1048576
- `tab_width` (integer, optional): min 1; max 16
- `leading_only` (boolean, optional)

## Output

- `text` (string, required): max length 4194304
- `replacements` (integer, required): min 0

## Limits

- max text bytes: 1048576
- max output bytes: 4194304

## Example

Request input:

```json
{
  "text": "\t\tHello\tWorld",
  "tab_width": 2,
  "leading_only": true
}
```

Response:

```json
{
  "result": {
    "text": "    Hello\tWorld",
    "replacements": 2
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "text-tabs-to-spaces",
  "version": "1.0.0",
  "input": {
    "text": "\t\tHello\tWorld",
    "tab_width": 2,
    "leading_only": true
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/text-tabs-to-spaces/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"text":"\t\tHello\tWorld","tab_width":2,"leading_only":true}'
```

The machine-readable contract is at [/v1/tools/text-tabs-to-spaces/versions/1.0.0](/v1/tools/text-tabs-to-spaces/versions/1.0.0).

### CLI

```sh
node cli.mjs run text-tabs-to-spaces 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [Text indentation detect](/tools/text-indentation-detect): Detect whether a text uses tabs or spaces for indentation by counting lines.
- [Text line endings normalize](/tools/text-line-endings-normalize): Normalize all line endings in a text to a specific format (LF, CRLF, or CR).
- [Text apply unified patch](/tools/text-apply-unified-patch): Apply a one-file unified patch to text at original line addresses with exact hunk matches.
- [Text prefix suffix check](/tools/text-prefix-suffix-check): Exact prefix and/or suffix boolean checks using JS string startsWith/endsWith.
- [Text replace exact](/tools/text-replace-exact): Replace exact UTF-16 substrings without regex, case folding, or Unicode normalization.
- [Text three way merge](/tools/text-three-way-merge): Three-way merge of text line records with merge or diff3 conflict markers.
