# Add \`editor::InsertSnippet\` action \(\#44428\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/6b2d1f153d052e21b8ae0dbf56cd6fd84e389b10)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 6b2d1f153d052e21b8ae0dbf56cd6fd84e389b10

Requested commit: 6b2d1f153d052e21b8ae0dbf56cd6fd84e389b10

Commit: 6b2d1f153d052e21b8ae0dbf56cd6fd84e389b10

Tree: 413a86b839f74fce864ed4af237c73f37921d6e5

Author: Andrew Farkas

Committer: GitHub

## Message

````
Add `editor::InsertSnippet` action (#44428)

Closes #20036

This introduces new action `editor: insert snippet`. It supports three
modes:

```
["editor::InsertSnippet", {"name": "snippet_name"}]
["editor::InsertSnippet", {"language": "language_name", "name": "snippet_name"}]
["editor::InsertSnippet", {"snippet": "snippet with $1 tab stops"}]
```

## Example usage

### `keymap.json`

```json
  {
    "context": "Editor",
    "bindings": {
      // named global snippet
      "cmd-k cmd-r": ["editor::InsertSnippet", {"name": "all rights reserved"}],
      // named language-specific snippet
      "cmd-k cmd-p": ["editor::InsertSnippet", {"language": "rust", "name": "debug-print a value"}],
      // inline snippet
      "cmd-k cmd-e": ["editor::InsertSnippet", {"snippet": "println!(\"This snippet has multiple lines.\")\nprintln!(\"It belongs to $1 and is very $2.\")"}],
    },
  },
```

### `~/.config/zed/snippets/rust.json`

```json
{
  "debug-print a value": {
    "body": "println!(\"$1 = {:?}\", $1)",
  },
}
```

### `~/.config/zed/snippets/snippets.json`

```json
{
  "all rights reserved": {
    "body": "Copyright © ${1:2025} ${2:your name}. All rights reserved.",
  },
}
```

## Future extensions

- Support multiline inline snippets using an array of strings using
something similar to `ListOrDirect` in
`snippet_provider::format::VsCodeSnippet`
- When called with no arguments, open a modal to select a snippet to
insert

## Release notes

Release Notes:

- Added `editor::InsertSnippet` action
````

## Parents

- [22e1bcccadac6cc98e8f2610182531cc24e395e5](https://git.cafe/gitcafe/zed/commit/22e1bcccadac6cc98e8f2610182531cc24e395e5?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/6b2d1f153d052e21b8ae0dbf56cd6fd84e389b10?format=markdown)
