My goal is to create a VSCode snippet with body content that can be populated with any number of inputs and optionally inserting another placeholder, an indeterminate number of times until I decide to move on to the next, fixed order tabstop.
As an example, I'm trying to create a snippet that serves as a template for writing other snippets in JSON format.
The following is a simple implementation in which the snippet name, prefix list, body list, and description.
"simple snippet template": {
"prefix": ["snippet_template_simple"],
"body": ["\"${1:snippet_name}\": {",
"\t\"prefix\": [\"${2}\"],",
"\t\"body\": [\"${3}\"],",
"\t\"description\": \"$4\"",
"}$0"],
"description": "Template for creating a snippet"
},
In the case that I would like multiple entries in the prefix and body lists, I would like to include placeholders that include a comma and quotation marks. My intention is that when I'm typing such placeholders while using the snippet, another placeholder will repeatedly appear within the prefix/body lists, until I delete/backspace to move on to the next, fixed-order placeholder (e.g. the description placeholder once I'm finished listing all of the entries to the body list).
The following is an attempt of mine to move toward my goal, with nested placeholders representing a 2nd entry to each of the prefix/body lists. After I populate placeholder $2, I can hit TAB to move to $3 and then either hit TAB again to move to $4 and type another entry for the prefix table, or hit Backspace to move onto $5 and the body list.
"snippet template2": {
"prefix": ["snippet_template_2"],
"body": ["\"${1:snippet_name}\": {",
"\t\"prefix\": [\"${2}\"${3:,\"${4}\"}],",
"\t\"body\": [\"${5}\"${6:,\"${7}\"}],",
"\t\"description\": \"$8\"",
"}$0"],
"description": "Template for creating a snippet"
}
It's clear that my proposed example saves little in terms of typing and effort, but it could serve as an example for other use cases in which one would want to design a snippet that incorporates an indeterminate number of repeated elements.
I've explored questions that discuss regex, multi-cursor, and defining a second snippet to be inserted via the first snippet, but I've not yet been able to achieve my goal.