Sublime Forum

About snippet control mutiple fields

#1

aa${1:bb}cc${2:dd}ee${1:ff}
Take above code as an example.
When i trigger this snippet, it shows: aabbccddeebb.
Apparently, what i want should be: aabbccddeeff.
The preset value of second $1 was made to the first $1. How do i avoid this?

0 Likes

#2

You can use the same field (number) multiple times in your snippet, but you can only supply a single default value as they will hold the same content.

Did you perhaps want the last field to be ${3:ff}?

0 Likes

#3

If i delete $1, ‘bb’ and ‘ff’ should both be deleted, if i choose not delete $1, ‘bb’ and ‘ff’ will remain the default value and i don’t need to modify the second $1 because it’s ‘ff’ already. That’s what i was expeced. This is userful when more $1 is applied:
aa${1:bb}cc${2:dd}ee${1:ff}gg{$1:hh}ii${1:jj}…

Maybe there will be a solution using regular expression, but i don’t know much about that.

0 Likes

#4

there is no regular expression for snippet

0 Likes

#5

Use this to insert ff, if $1 is present:

aa${1:bb}cc${2:dd}ee${1/.+/(?0:ff)/g}
4 Likes