Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

User-defined snippets

Snippets insert reusable text with placeholders you can fill in. They appear in completion without a language server, and you can insert them from a picker or a key binding.

Create a snippet

Run :snippet-open to open snippets.toml in your Mitos configuration directory. Add a definition, save the file, and run :snippet-reload:

[[snippet]]
name = "Error check"
prefix = ["err", "iferr"]
scope = "go"
description = "Return an error from the current function"
body = '''if ${1:err} != nil {
    return $1
}
$0'''

In a Go file, type err and accept the snippet from the completion menu. Replace the selected err, then use placeholder navigation to finish editing.

FieldMeaning
nameRequired, unique name used in the picker and :snippet-insert.
bodyRequired, nonempty snippet text, or an array of lines joined with newlines.
prefixTrigger text or a list of triggers. Omit to use only the picker or :snippet-insert.
scopeLanguage name from languages.toml, or a list of names. Omit to use in every language, including plain text.
descriptionOptional explanation shown in completion and the picker.

For example, the body above can also be written as:

body = ["if ${1:err} != nil {", "    return $1", "}", "$0"]

Prefixes may contain punctuation, such as for-const or for!, but no whitespace or control characters. Press Ctrl-x to request completion after punctuation; automatic completion is triggered by word characters. Accepting a snippet replaces its matching prefix at each cursor. Different snippets may share a prefix.

Language scopes follow embedded languages at the cursor when syntax information is available. To disable user snippet suggestions, set editor.completion.snippets = false. The picker and named insertion remain available. Language-server snippets have a separate setting, editor.lsp.completion.snippets.

Organize snippets in several files

Keep definitions in snippets.toml, split them across .toml files in the sibling snippets/ directory, or use both:

~/.config/mitos/
  snippets.toml
  snippets/
    rust.toml
    go/
      errors.toml
      http.toml

Each file uses the same [[snippet]] format and may contain several definitions. Subdirectories are included. Filenames only organize the collection: set scope in each definition to choose its languages. Names must be unique across all user snippet files. Duplicate-name errors identify both files.

Run :snippet-open go/http.toml to open a file in snippets/. Mitos creates missing parent directories; save the file to create it. The filename must be a relative .toml path. Other extensions and directory symlinks are ignored when loading collections; symlinks to regular files are supported.

After adding, editing, renaming, or deleting files, run :snippet-reload. :config-reload also reloads snippets. If any file contains an error, the reload reports it and your previous snippets remain available.

Share snippets with a project

Put project definitions in .mitos/snippets.toml or .toml files under .mitos/snippets/ at the workspace root. They use the same format and become available after you trust the workspace.

Names must be unique within the project collection. A project snippet with the same name as a user snippet replaces it, including its triggers and language scope. Removing the project definition and reloading restores the user snippet. Other user snippets remain available. Each workspace uses its own project snippets.

Use :snippet-open-workspace to edit the project’s primary file, or :snippet-open-workspace go/http.toml to edit a file in its snippet directory. Save and reload as above. Changes to trusted project settings may require you to renew workspace trust.

Browse and insert snippets

Bind snippet_picker to browse snippets available in the current language:

[keys.normal]
A-s = "snippet_picker"

The picker shows names, triggers, descriptions, and source files. Select a snippet and press Enter to insert it. If Mitos asks you to reopen the picker, choose the snippet again.

To bind a particular snippet directly, use its exact name:

[keys.normal]
A-e = ':snippet-insert "Error check"'

Insertion replaces selected text in select mode and enters insert mode with the first placeholder selected. Larger selections and active placeholders are also replaced in other modes. A single insert cursor inserts before the character under it. Use $TM_SELECTED_TEXT to wrap selected text:

[[snippet]]
name = "Parenthesize selection"
body = '(${TM_SELECTED_TEXT})$0'
CommandAction
snippet_pickerBrowse and insert snippets for the current language.
:snippet-insert <name>Insert a snippet by its exact name.
:snippet-open [file]Open the user snippet file, or a named file in snippets/.
:snippet-open-workspace [file]Open the project snippet file, or a named file in .mitos/snippets/.
:snippet-reloadReload user and open workspace snippets.

Write snippet bodies

Bodies use the same syntax as language-server snippets:

SyntaxEffect
$1, $2Editable positions, visited in number order. Repeated numbers are edited together.
${1:default}A placeholder with selected default text. Defaults may contain other placeholders.
$0Final cursor position after the last placeholder.
`${1one,two,three
$NAME, ${NAME:default}Insert a variable, with an optional fallback.
${NAME/regex/replacement/}Transform a variable before inserting it.

Use placeholder navigation to move forward and backward. For choice placeholders, type a replacement or bind commands to cycle the available values:

[keys.insert]
A-n = "snippet_next_choice"
A-p = "snippet_previous_choice"

Use TOML literal strings ('...' or '''...''') to avoid a second layer of backslash escaping. Write \$ for a literal dollar sign, \} for a literal closing brace, and \\ for a literal backslash. In a choice, escape a literal comma or pipe with \, or \|. Use actual tabs or spaces for indentation in literal strings; Mitos adapts indentation to the document.

For example, this inserts the filename without its final extension in uppercase:

body = '${TM_FILENAME/(.*)\..+$/${1:/upcase}/}'

Transforms use Rust regular expressions, with g (all matches), i (ignore case), and m (multiline) flags. Regex features from other editors, such as lookaround and backreferences in the pattern, are not supported. Snippet bodies contain text and do not execute shell commands or other code. Regex transforms of editable placeholders, such as ${1/regex/replacement/}, are not supported.

Variables

These names work in both user-defined and language-server snippets, regardless of programming language. Comment variables use the language at each cursor. Text and cursor variables use each cursor’s text and selection.

Unknown or unavailable variables insert their fallback, or an empty string when no fallback is given. For example, ${TM_FILENAME:untitled} inserts untitled in an unsaved buffer. A transform receives an empty string when its variable is unavailable. A single insert cursor does not count as selected text; use select mode to wrap one character.

Text, files, and workspace

VariableValue
TM_SELECTED_TEXT, SELECTIONSelected text.
TM_CURRENT_LINECurrent line without its line ending.
TM_CURRENT_WORDWord at the cursor.
TM_LINE_INDEX, TM_LINE_NUMBERCurrent line number, starting at 0 or 1 respectively.
CURSOR_INDEX, CURSOR_NUMBERCursor number, starting at 0 or 1 respectively.
TM_FILENAMEFilename, including its extension.
TM_FILENAME_BASEFilename without its final extension.
TM_DIRECTORYFull path of the file’s parent directory.
TM_FILEPATHFull path of the file.
RELATIVE_FILEPATHFile path relative to the workspace root.
WORKSPACE_NAMEWorkspace directory name.
WORKSPACE_FOLDERFull path of the workspace root.
CLIPBOARDSystem clipboard contents, when available.
LINE_COMMENTLine comment marker, such as // in Rust.
BLOCK_COMMENT_START, BLOCK_COMMENT_ENDBlock comment markers, such as /* and */ in Rust.

Date and time

Dates use local time. Month and weekday names are English.

VariableValue or example
CURRENT_YEAR, CURRENT_YEAR_SHORTYear, such as 2026 or 26.
CURRENT_MONTHTwo-digit month, such as 02.
CURRENT_MONTH_NAME, CURRENT_MONTH_NAME_SHORTMonth name, such as July or Jul.
CURRENT_DATETwo-digit day of the month, such as 08.
CURRENT_DAY_NAME, CURRENT_DAY_NAME_SHORTWeekday name, such as Monday or Mon.
CURRENT_HOURTwo-digit hour in the 24-hour clock.
CURRENT_MINUTE, CURRENT_SECONDTwo-digit minute or second.
CURRENT_MILLISECONDThree-digit millisecond, such as 078.
CURRENT_SECONDS_UNIXSeconds since the Unix epoch.
CURRENT_MILLISECONDS_UNIXMilliseconds since the Unix epoch.
CURRENT_TIMEZONE_OFFSETUTC offset, such as +02:00 or -07:00.
CURRENT_TIMEZONE_NAMEIANA time zone name, when available, such as Europe/Berlin.

Random values

VariableValue
RANDOMSix random decimal digits.
RANDOM_HEXSix random hexadecimal digits.
UUIDA version 4 UUID.

Each cursor gets its own random values. Repeated references within one snippet use the same value. For user snippet completions, the preview shows the values that will be inserted when you accept the suggestion.