Skip to main content

Snippets and templates

Snippets are reusable blocks of Markdown you can insert while editing. Templates are whole starter documents.

A Pro feature

Inserting a snippet needs editing turned on, so it is part of Twain Pro. File ▸ New from Template and Edit Snippets… work without Pro.

Inserting a snippet

While editing, choose Format ▸ Insert Snippet and pick one. Snippets are always inserted into the source pane, at that pane's own cursor, and focus moves there. The command therefore needs the source on screen: use the side-by-side or raw view, because in the rendered-only view it does nothing. Twain ships with these built-in snippets:

  • Table: a GitHub-style table skeleton
  • Callout: an MDX callout block
  • Frontmatter: a YAML frontmatter block
  • Mermaid diagram: a fenced Mermaid block
  • MDX component: a starter component block

Placeholders

Snippets can contain placeholders that let you tab through the parts you need to fill in. A snippet using ${1:default}, ${2}, $3 and so on selects the first placeholder's default text when it is inserted, so typing replaces it; press Tab to move to the next one. A final $0 (or ${0}) marks where the cursor ends up. Write \$ for a literal dollar sign.

The tab cycle is dropped as soon as you undo, redo, or make an edit Twain cannot account for, rather than risk aiming the next Tab at unrelated text. After that, Tab inserts a tab character as usual.

Editing and adding your own

Choose Format ▸ Insert Snippet ▸ Edit Snippets… to open your snippets file. Snippets are stored as JSON in Twain's Application Support folder. If the file does not exist yet, Twain seeds it with an example you can edit.

A snippet you define with the same name as a built-in replaces that built-in; a new name adds to the list.

Templates

File ▸ New from Template creates a new document from a starter template. The built-in templates are Blog Post, README, Meeting Notes, and Technical Doc. Twain asks where to save the new file, suggesting the template name in lower case with hyphens plus .md, then opens it.

Templates use the same placeholder syntax as snippets, but a new document is written with every placeholder already replaced by its default text (or removed, where it has none). There is no tab cycle to step through, and the $0 marker simply disappears.