-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSnippet.txt
50 lines (49 loc) · 7.32 KB
/
Snippet.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
:Snippet:
Usage: Type a few character → press Tab → a template of text is inserted
Stored in *.sublime-snippet located under any package’s folder
Appear under Tools | Snippets | <Your Package>.
Tools > New Snippet... → Sublime Text will present a snippet skeleton
Each *.sublime-snippet can only contain 1 snippet. To host multiple ones, use [[AutoComplete.txt#.sublime-completions]]
Use keybinding, We can
load specific snippet, i.e: { "keys": ["%"], "command": "insert_snippet", "args": {"name": "Packages/XML/long-tag.sublime-snippet"} }
insert snippet without creating a .sublime-snippet file, i.e: { "keys": ["%"], "command": "insert_snippet", "args": {"contents": "%$0%"} }
Example of .sublime-snippet:
<snippet>
<content>=dword:00000001</content> //template of text to be inserted
<tabTrigger>=d</tabTrigger> //Optional: Press this sequence of keys then Tab to insert snippet
<scope>source.reg</scope> //Optional: limit the use of snippet to certain scope [[Scope.txt]]
<description>dword in .reg file</description> //Optional: Description to display in Snippets menu
</snippet>
content:
Example: assert ${1:condition}, ${2:message}, ${3:continue=0}
Must not contain ]]> → Work around: insert an undefined/empty variable i.e: ]]$NOT_DEFINED>
$ must be escaped with \$
Always use tabs for indentation → on execute, tab is transformed to spaces if "translateTabsToSpaces": true
Field markers $1 $2 $3 ... $n
Tab/Shift+Tab will cycle cursor position through each field
If field is repeated:
First Name:$1, Last Name:$2, Full Name:$1 $2
Multiple cursors appear at both positions → edit multiple fields at the same time
$0 Specify exit point (cursor position after pressing Tab at the last fiels)
Placeholders:
Define default values i.e: First Name: ${1:Guillermo}, Second Name: ${2:López}
Can nest placeholders i.e: Test: ${1:Parent ${2:Nested}}
Can use variable
Environment variables i.e: $TM_FULLNAME, $TM_FILENAME, $TM_TAB_SIZE, $TM_SOFT_TABS
Custom variables defined in .sublime-options
Example: User name: ${1:$TM_FULLNAME}, Tab equal $TM_TAB_SIZE spaces
Full list of variables:
| $PARAM1 .. $PARAMn | Arguments passed to the insertSnippet command. |
| $SELECTION | The text that was selected when the snippet was triggered. |
| $TM_CURRENT_LINE | Content of the line the cursor was in when the snippet was triggered. |
| $TM_CURRENT_WORD | Current word under the cursor when the snippet was triggered. |
| $TM_FILENAME | Filename of the file being edited including extension. |
| $TM_FILEPATH | Path to the file being edited. |
| $TM_FULLNAME | User’s user name. |
| $TM_LINE_INDEX | Column where the snippet is being inserted, 0 based. |
| $TM_LINE_NUMBER | Row where the snippet is being inserted, 1 based. |
| $TM_SELECTED_TEXT | An alias for $SELECTION. |
| $TM_SOFT_TABS | YES if translateTabsToSpaces is true, otherwise NO. |
| $TM_TAB_SIZE | Spaces per-tab (controlled by the tabSize option). |
Advanced example:
%${0:$SELECTION}% //wrap current selection in a pair of %