Skip to content

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 namesnippets
Moduleuser/snippets.rs
Definitionsuser/snippets/<language_id>/*.vsnip
Autocomplete Provider idsnippets

What it does ​

  • Loads one Snippet Definition per .vsnip file under user/snippets/<language_id>/
  • Registers Autocomplete Provider snippets (after LSP; no or_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 ​

CommandDescription
snippet.nextMoves to the next Insert Point in Snippet Mode.
snippet.previousMoves to the previous Insert Point in Snippet Mode.
snippet.cancelLeaves 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).

ChordCommandScope
Tabsnippet.nextSnippet (Insert)
Shift+Tabsnippet.previousSnippet (Insert)
Escapesnippet.cancelSnippet (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 / labelsnippets / Snippets
Registrationuser/autocomplete.rs backends() — immediately after lsp
Or-groupNone (always merges; does not compete in source)
ItemsBuilt 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:

FieldMeaning
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::

BlockMeaning
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.

text
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.

Volt — modal editor platform · docs optimized for in-editor help search