Meaning of Visual placeholders on default snippets

Asked by mMontu

What is the purpose of the visual placeholder on the default snippets?
For example, the snippet below, from ultisnips / UltiSnips / c.snippets

snippet #if "#if #endif" b
#if ${1:0}
${VISUAL}${0:${VISUAL/(.*)/(?1::code)/}}
#endif
endsnippet

, has two visual placeholders and a transformation on the second one.

As far as I understand, it is equivalent to

snippet #if "#if #endif" !b
#if ${1:0}
${0:${VISUAL:code}}
#endif
endsnippet

But if someone get the trouble to write the first, more complex version, it should be due to some good reason that I can't see.

Maybe this was already explained somewhere, but I was unable to find.

Question information

Language:
English Edit question
Status:
Solved
For:
UltiSnips Edit question
Assignee:
No assignee Edit question
Solved by:
SirVer
Solved:
Last query:
Last reply:
Revision history for this message
Best SirVer (sirver) said :
#1

${VISUAL}${0:${VISUAL/(.*)/(?1::code)/}}

Means: if you have visual selection, insert it and leave my cursor after it. Otherwise write 'code' and select it for overwrite.

${0:${VISUAL:code}}

Means: if you have visual selection, insert it and select it for overwriting, otherwise insert 'code' and select it for overwriting.

Probably best would have been here:

${VISUAL}${0}

since the word 'code' is more of a nuisance than a helper really.

Revision history for this message
mMontu (mmontu) said :
#2

Thanks SirVer, that solved my question.