---
title: "text.insert: Insert text — Note kit command — Kition"
description: "Inserts `text` at a text position (from 0) and answers the note's new length. Get positions from `text.find`; inserting at 0 puts text above the front matter."
canonical: "https://developer.kition.ai/docs/kits/note/commands/text.insert"
---

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

# text.insert

**Insert text.** Inserts `text` at a text position (from 0) and answers the note's new length. Get positions from `text.find`; inserting at 0 puts text above the front matter.

- 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 |
| --- | --- | --- | --- |
| `at` | `integer` | yes | Where to insert. |
| `expected` | `string` | no | What the empty range at `at` holds: ""; any other text fails the insert. |
| `text` | `string` | yes | The Markdown to insert. |
| `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.insert", "params": { "at": <integer>, "text": <string> } }]
}
```

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": {
    "at": {
      "description": "Where to insert.",
      "type": "integer"
    },
    "expected": {
      "description": "What the empty range at `at` holds: \"\"; any other text fails the insert.",
      "type": "string"
    },
    "text": {
      "description": "The Markdown to insert.",
      "type": "string"
    },
    "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": [
    "at",
    "text"
  ],
  "type": "object"
}
```

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