Skip to content

Snippets

Snippets are templates that expand from a short prefix. Type the prefix, pick the snippet from the completions menu, and press tab to move through its tab stops.

Create a snippet

  1. Open the command palette (cmd-shift-p) and run snippets: configure snippets.
  2. Pick a scope in the Select snippet scope… list. A language scope applies to that language only. The global scope applies everywhere.
  3. Tyrn opens the snippets file for that scope. Add your snippet and save.

Snippet files live in ~/.config/tyrn/snippets. Run snippets: open folder to show the folder in Finder.

javascript.json
{
// A snippet needs a name and a body. The prefix and description are optional.
// When there is no prefix, the name triggers the snippet.
"Log to console": {
"prefix": "log",
"body": ["console.info(\"Hello, ${1:World}!\")", "$0"],
"description": "Logs to console"
}
}
  • $1, $2 and ${1:default} are tab stops. ${1:default} fills in a default you can overtype.
  • $0 is where the cursor ends up.
  • Tab stops with the same number are linked, so typing in one types in all.
  • To write a literal $ outside a placeholder, escape it as \\$.

While a snippet is active, tab moves to the next tab stop and shift-tab to the previous one.

Scopes

The file name is the language name in lowercase, for example python.json for Python. A few names are special:

Scope File name
Global snippets.json
JSX javascript.json
Plain text plaintext.json

JSX snippets go in javascript.json, not jsx.json. TSX and TypeScript use their own names. Slashes in a language name are dropped from the file name.

Limits

  • Only the .json format is supported.
  • If a snippet has a list of prefixes, only the first is used.

Where snippets show up

Snippets appear in the completions menu alongside language server results. Change where they sort with snippet_sort_order ("top", "inline" default, "bottom" or "none"). Language extensions can also ship snippets. See Languages.