Snippets Plugin
Help query: "What does the snippets plugin do?" / "How do I use snippets in Volt?" / "How do I write a .vsnip file?" / "What is Snippet Mode?"
The snippets plugin loads Snippet Definitions from .vsnip files, offers them through an Autocomplete Provider, and drives Snippet Mode so you can Tab among Insert Points after accept. Definitions and expand logic live in the User Library (user/snippets.rs); the host owns Snippet Mode and buffer edits.
| Package name | snippets |
| Module | user/snippets.rs |
| Definitions | user/snippets/<language_id>/*.vsnip |
| Autocomplete Provider id | snippets |
What it does
- Loads one Snippet Definition per
.vsnipfile underuser/snippets/<language_id>/ - Registers Autocomplete Provider
snippets(after LSP; noor_group, so items always merge) - On accept, inserts the expansion and enters Snippet Mode (Insert + Minor Mode)
- Binds Tab / Shift+Tab / Escape while Snippet Mode is active
Snippet Mode is skipped when multicursor is active (no snippet items offered).
Commands
| Command | Description |
|---|---|
snippet.next | Moves to the next Insert Point in Snippet Mode. |
snippet.previous | Moves to the previous Insert Point in Snippet Mode. |
snippet.cancel | Leaves Snippet Mode and returns to Insert. |
Hooks: ui.snippet.next, ui.snippet.previous, ui.snippet.cancel.
Keybindings
Active only in Snippet keymap scope while Insert (host enters that Minor Mode after accept).
| Chord | Command | Scope |
|---|---|---|
Tab | snippet.next | Snippet (Insert) |
Shift+Tab | snippet.previous | Snippet (Insert) |
Escape | snippet.cancel | Snippet (Insert) |
Tab past the last Insert Point leaves Snippet Mode and stays in Insert. $0 is the first landing after accept; numbered stops advance in order.
Autocomplete Provider
| Id / label | snippets / Snippets |
| Registration | user/autocomplete.rs backends() — immediately after lsp |
| Or-group | None (always merges; does not compete in source) |
| Items | Built at query time from matching .vsnip files for the buffer language |
Trigger matching: non-empty prefix where the definition trigger starts with the prefix. Accept uses the usual autocomplete accept chord (Ctrl+y).
Authoring .vsnip
One file = one Snippet Definition. Required fields:
| Field | Meaning |
|---|---|
name: | Autocomplete label |
trigger: | Prefix that offers the item (for example ///) |
target: | next <kind> or enclosing <kind> (tree-sitter node kind) |
body: | Template lines; remaining lines until EOF |
Optional projections before body::
| Block | Meaning |
|---|---|
each <id>: | Repeat line: once per capture under the target (path: + line:) |
maybe <id>: | Zero or one emission; returns omits empty/void |
Body markers:
$0,$1, … — Insert Points (Snippet Mode)${id}— hole filled by a projection block with that id- In projection
line:,$${i}— auto-numbered Insert Point;${name}(last path segment) — capture text
Example (C#)
Shipped sample: user/snippets/csharp/xmldoc.vsnip — trigger /// on the next method_declaration, expands XML doc summary / params / returns.
name: csharp-xmldoc
trigger: ///
target: next method_declaration
each params:
path: parameter/name
line: /// <param name="${name}">$${i}</param>
maybe returns:
path: returns
line: /// <returns>$${i}</returns>
body:
/// <summary>
/// $0
/// </summary>
${params}
${returns}Rebuild the user package after adding or editing definitions (cargo build -p volt-user, or workspace.compile).
Notes
- Architecture split (User Library engine vs host Snippet Mode) is recorded in Volt ADR 0010 (Snippets engine in User Library; host owns mode and query primitives).
- Provider wiring and or-group rules: Autocomplete providers.