# Reference: snippets > Neutral description of the snippets files, the Snippets menu, and how a snippet is inserted. ## Files Both are read, and both are optional. | File | Holds | | --- | --- | | `./.turbo-rust/snippets.toml` | The project's snippets | | `$TURBO_RUST_SNIPPET_DIR/snippets.toml`, else `/turbo-rust/snippets.toml` | Your own, shared across projects | `` is `os.UserConfigDir()`: `~/.config` on Linux, `~/Library/Application Support` on macOS. | Property | Value | | --- | --- | | Project search | The working directory only. Parent directories are **not** searched. | | Read | Every time the Snippets menu opens | | Order | Your own first, then the project's | | Name clash | Same `group` **and** `name` → the project's replaces yours | | Missing file | Not an error | | Unreadable file | An error, shown in the menu | ## File format One `[[snippet]]` table per snippet. | Key | Type | Required | Description | | --- | --- | --- | --- | | `name` | string | yes | What the menu shows | | `body` | string | yes | The text inserted at the cursor | | `group` | string | no | The submenu it goes in; absent means `General` | | `languages` | array of strings | no | Restricts the snippet to those languages; absent means every file | `languages` uses the editor's own language names: `rust`, `toml`, `yaml`, `markdown`, `javascript`, `html`, `xml`, `dockerfile`, `bash`. See [Languages coloured](languages.md). A snippet with no `name` or no `body` makes the whole file an error — it could not be shown or could not be inserted. ### Example ```toml [[snippet]] name = "if err != nil" group = "Rust" languages = ["rust"] body = """ if err != nil { return err }""" ``` TOML's `"""` strings drop the newline immediately after the opening quotes, and interpret `\t` as a tab. ## The menu | Item | Condition | | --- | --- | | One submenu per group, in the order the groups first appear in the files | A group with at least one snippet applying to the front window | | `Cannot read snippets`, greyed out | A file is present but unreadable | | `Create snippets file` | The project has no snippets file | | `Open snippets file` | The project has one | The menu's hot key is `Alt-N`, not `Alt-S`: Search already answers to S. Groups, and the snippets inside them, come out in the order they were read, so the menu matches the files. A snippet item is greyed out when there is no file open to insert into — a terminal or the project tree in front counts as no file. ### Filtering | Front window | Snippets offered | | --- | --- | | A file of a recognised language | Those naming that language, plus those naming none | | A file of no recognised language | Those naming none | | A terminal, the project tree, or nothing | Those naming none | ## Insertion | Behaviour | Detail | | --- | --- | | Position | At the cursor | | First line | Inserted where the cursor is | | Later lines | Prefixed with the leading whitespace of the line the cursor was on | | Blank lines in the body | Left blank, not padded with whitespace | | Undo | One step for the whole snippet | | Cursor after | At the end of the inserted text | | Report | `Snippet inserted` on the status bar | The indent copied is the **whitespace prefix of the current line**, tabs or spaces as they were, so a snippet follows whatever the file already uses. ## Menu items | Item | Menu | Effect | | --- | --- | --- | | Create snippets file | Snippets | Writes `.turbo-rust/snippets.toml` with worked examples, then opens it. Greyed out once the project has one. | | Open snippets file | Snippets | Opens `.turbo-rust/snippets.toml`. Greyed out until the project has one. Always the project's file, never your own — it is the file the item above it writes. | The file is written through a temporary file in the same directory, renamed into place, so an interrupted write leaves the previous file intact. ## Errors | Message | Cause | | --- | --- | | `Cannot read snippets` in the menu | A snippets file is present but not valid TOML, or holds a snippet with no name or no body | | `Already there: .turbo-rust/snippets.toml` | Creating in a project that already has one. Unreachable from the menu, which greys the item out; still possible for a caller that is not a menu. | | `This project has no .turbo-rust/snippets.toml yet.` | Opening in a project that has none, likewise | | `Cannot tell which directory this is: …` | The working directory could not be read | ## See also - [How to insert snippets from a menu](../how-to/use-snippets.md) - [Snippets](../explanation/snippets.md) - [Keyboard](keyboard.md)