Find myself frequently invoking a snippet within a snippet, but of course when I go to expend the nested snippet, the tab key moves me to either the next entry of the first snippet or the end of the first snippet (at which point, I have to replace the cursor at the end of the tab-trigger expression for the 2nd snippet and hit tab, at which point the 2nd snippet is expanded).
eg. given snippet [ content A ${1:First point in A} and ${2: Second point in A} ]
with tab-trigger tabtrigA
and snippet [ content B ]
with tab-trigger tabtrigB
I'd like to be able to do the following:
In[1]:
tabtrigA % Hit tab to expand snippet A
Out[1]:
[ content **A First point in A** and ${2: Second point in A} ] % where everything between ** ** is highlighted
Now replace **...**
content with tabtrigB
In[2]:
[ content tabtrigB* and ${2: Second point in A} ] % where * marks location of cursor.
and hitting tab
would result in:
Out[2]:
[ content [ content B ]* and ${2: Second point in A} ] % where * marks location of cursor
and hitting tab
again would then jump to second entry of snippet A
Obviously this is tiresome: is it possible to switch the priority assignment of tab
so that it first acts as a tab-trigger and only jumps to next entry if there is no tab-trigger?
Update: as of April 2019, still no solution for triggering a snippet within a snippet.
I don't think sublime can tell this snippets' next_field from that snippet's next_field. You can only ask if it has_next_field, any. But you could go with workarounds:
command palette
by giving your nested snippet a description
. The snippet below will be callable from the palette as Snippet: description_for_command_palette.<snippet>
<content><![CDATA[
[ content B ]
]]></content>
<description>description_for_command_palette</description>
</snippet>
{ "keys": ["ctrl+0"], "command": "insert_snippet", "args": {"name": "Packages/User/your_snippet.sublime-snippet"}}
{ "keys": ["ctrl+0"], "command": "insert_snippet", "args": {"contents": "[ content B ]"}}
Just add two keybindings:
{ "keys": ["enter"], "command": "next_field", "context":
[
{ "key": "has_next_field", "operator": "equal", "operand": true }
]
},
{ "keys": ["tab"], "command": "insert_best_completion", "args": {"default": "\t", "exact": false}, "context":
[
{ "key": "has_next_field", "operator": "equal", "operand": true }
]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With