You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 8, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+23-3Lines changed: 23 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,26 +13,46 @@ Snippets files are stored in a package's `snippets/` folder and also loaded from
13
13
'.source.js':
14
14
'console.log':
15
15
'prefix':'log'
16
+
'command':'insert-console-log'
16
17
'body':'console.log(${1:"crash"});$2'
17
18
```
18
19
19
20
The outermost keys are the selectors where these snippets should be active, prefixed with a period (`.`) (details below).
20
21
21
22
The next level of keys are the snippet names.
22
23
23
-
Under each snippet name is a `prefix` that should trigger the snippet and a `body` to insert when the snippet is triggered.
24
+
Under each snippet name is a `body` to insert when the snippet is triggered.
24
25
25
-
`$` followed by a number are the tabs stops which can be cycled between by pressing <kbd>tab</kbd> once a snippet has been triggered.
26
+
`$` followed by a number are the tabs stops which can be cycled between by pressing <kbd>Tab</kbd> once a snippet has been triggered.
26
27
27
-
The above example adds a `log` snippet to JavaScript files that would expand to.
28
+
The above example adds a `console.log` snippet to JavaScript files that would expand to:
28
29
29
30
```js
30
31
console.log("crash");
31
32
```
32
33
33
34
The string `"crash"` would be initially selected and pressing tab again would place the cursor after the `;`
34
35
36
+
A snippet must define **at least one** of the following keys:
37
+
38
+
### The ‘prefix’ key
39
+
40
+
If a `prefix` is defined, it specifies a string that can trigger the snippet: type the string in the editor and press <kbd>Tab</kbd>. In this example, typing `log` (as its own word) and then pressing <kbd>Tab</kbd> would replace `log` with the string `console.log("crash")` as described above.
41
+
42
+
Prefix completions can be suggested if partially typed thanks to the `autocomplete-snippets` package.
43
+
44
+
### The ‘command’ key
45
+
46
+
If a `command` is defined, it specifies a command name that can trigger the snippet. That command can be invoked from the command palette or mapped to a keyboard shortcut via your `keymap.cson`.
47
+
48
+
If you defined the `console.log` snippet described above in your own `snippets.cson`, it would be available in the command palette as “Snippets: Insert Console Log”, or could be referenced in a keymap file as `snippets:insert-console-log`.
49
+
50
+
If a package called `some-package` had defined that snippet, it would be available in the keymap as `some-package:insert-console-log`, or in the command palette as “Some Package: Insert Console Log”.
51
+
52
+
Invoking the command would insert the snippet at the cursor, replacing any text that may be selected.
53
+
35
54
### Optional parameters
55
+
36
56
These parameters are meant to provide extra information about your snippet to [autocomplete-plus](https://github.com/atom/autocomplete-plus/wiki/Provider-API).
37
57
38
58
*`leftLabel` will add text to the left part of the autocomplete results box.
0 commit comments