turbo-editors/turbo-rustpublic Fork 0
v1.0.2
Commits
Clone
git clone https://git.rickub.com/turbo-editors/turbo-rust.git
git clone ssh://git@rickub.com/turbo-editors/turbo-rust.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

use-snippets.md · 93 lines · 3.3 KBmarkdown Blame HistoryRaw
📦 Turbo Rust 713ea5c k33g 11h ago1# How to insert snippets from a menu
2
3This guide shows how to set up reusable pieces of text and put them into a file at the cursor. It assumes Turbo Rust is already installed.
4
5## Get a starter file
6
7Start the editor **from the project's own directory**, then choose **Snippets ▸ Create snippets file** (`Alt-N`, then `C`).
8
9That writes `.turbo-rust/snippets.toml`, filled in with a few worked examples, and opens it — coloured, because Turbo Rust colours TOML:
10
11```toml
12[[snippet]]
13name = "if err != nil"
14group = "Rust"
15languages = ["rust"]
16body = """
17if err != nil {
18 return err
19}"""
20
21[[snippet]]
22name = "TODO"
23body = "TODO: "
24```
25
26Each `[[snippet]]` becomes one line of the menu. The file is read every time the menu opens, so editing it takes effect immediately — no restart.
27
28## Insert one
29
30Open **Snippets** (`Alt-N`). Snippets sharing a `group` appear together in a submenu of that name; one with no group goes into **General**.
31
32| Key | Effect |
33| --- | --- |
34| `Alt-N`, or `F10` then `→` to Snippets | Open the menu |
35| `↑` `↓` | Move down the groups |
36| `→`, or `Enter` | Open the highlighted group |
37| `↑` `↓` then `Enter` | Insert the highlighted snippet |
38| `←` | Back out of a group |
39| `Escape` | Put the whole menu away |
40
41The snippet goes in at the cursor. **Lines after the first are indented to match the line you inserted it on**, so a multi-line snippet dropped into a nested block lands where you would have typed it:
42
43```
44func f() {
45 | ← cursor here
46}
47```
48
49becomes
50
51```
52func f() {
53 if err != nil {
54 return err
55 }
56}
57```
58
59It is one undo step: `Ctrl-Z` takes the whole snippet back out.
60
61## Keep snippets across every project
62
63Put them in `~/.config/turbo-rust/snippets.toml` — the same directory your own themes go in. Those appear in every project, and a project's own file adds to them rather than replacing them.
64
65Where a project and you use the same `name` in the same `group`, **the project's wins**: it is the more specific statement of the two.
66
67## Show a snippet only where it makes sense
68
69Add `languages`, using the names the editor uses — `rust`, `toml`, `markdown`, `javascript`, `html`, `bash`:
70
71```toml
72[[snippet]]
73name = "strict mode"
74group = "Shell"
75languages = ["bash"]
76body = "set -euo pipefail"
77```
78
79That snippet then appears only when a shell script is the front window. Leave `languages` out and the snippet is offered everywhere, which is what you want for a licence header or a `TODO`.
80
81A group left with nothing after filtering does not appear at all.
82
83## Variants
84
85- **You started the editor from a subdirectory.** The project's file is not found: only `./.turbo-rust` is looked at, the same rule `settings.toml` follows. Your own snippets still appear.
86- **The file has a mistake in it.** The menu shows a greyed-out `Cannot read snippets` where the groups would be, and **Create snippets file** is still there. Open the file and fix it.
87- **You want tabs in a body.** Write `\t`, as the starter file does — TOML turns it into a tab when it reads the file.
88
89## See also
90
91- Every key of the file and every rule: [Snippets reference](../reference/snippets.md)
92- Why the menu is rebuilt each time it opens, and why insertion re-indents: [Snippets](../explanation/snippets.md)
93- The other file in `.turbo-rust`: [Project settings](../reference/project-settings.md)