---
title: "text.replace: Replace text — Note kit command — Kition"
description: "Replaces the text between `from` and `to` with `text` and answers the note's new length; pass `expected` with the current text so a stale range fails."
canonical: "https://developer.kition.ai/docs/kits/note/commands/text.replace"
---

> Canonical HTML: [https://developer.kition.ai/docs/kits/note/commands/text.replace](https://developer.kition.ai/docs/kits/note/commands/text.replace)

# text.replace

**Replace text.** Replaces the text between `from` and `to` with `text` and answers the note's new length; pass `expected` with the current text so a stale range fails.

- Kit: Note 0.3.0 (Markdown (.md)); reference: [Note kit commands](https://developer.kition.ai/docs/kits/note.md)
- Changes the document: yes

## Parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `expected` | `string` | no | The text there now; the command is refused when it differs. |
| `from` | `integer` | yes | Where the range starts. |
| `text` | `string` | yes | The Markdown to put there. |
| `to` | `integer` | yes | Where the range ends (exclusive). |
| `unit` | `"scalar" \| "utf16"` | no | How positions are counted: Unicode characters (scalar, the default), or UTF-16 code units as the editor counts them. |

## Call through note_run

```text
note_run {
  "path": "<file>.md",
  "steps": [{ "command": "text.replace", "params": { "from": <integer>, "text": <string>, "to": <integer> } }]
}
```

The required parameters, with placeholders for their types: not a tested example. Optional: `expected`, `unit`. note_run answers the step’s result in `completed[i].result`.

## Result

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `length` | `integer` | yes | The note's length after the edit, in the request's unit. |

```json
{
  "additionalProperties": false,
  "properties": {
    "length": {
      "description": "The note's length after the edit, in the request's unit.",
      "type": "integer"
    }
  },
  "required": [
    "length"
  ],
  "type": "object"
}
```

## Parameter schema

```json
{
  "additionalProperties": false,
  "properties": {
    "expected": {
      "description": "The text there now; the command is refused when it differs.",
      "type": "string"
    },
    "from": {
      "description": "Where the range starts.",
      "type": "integer"
    },
    "text": {
      "description": "The Markdown to put there.",
      "type": "string"
    },
    "to": {
      "description": "Where the range ends (exclusive).",
      "type": "integer"
    },
    "unit": {
      "default": "scalar",
      "description": "How positions are counted: Unicode characters (scalar, the default), or UTF-16 code units as the editor counts them.",
      "enum": [
        "scalar",
        "utf16"
      ],
      "type": "string"
    }
  },
  "required": [
    "from",
    "text",
    "to"
  ],
  "type": "object"
}
```

Generated from kition-sdk packages/script/kits/note.ts and the kit itself (kition-note@69e14d9).
