3

What is the difference between them?

With ${VISUAL} :

snippet if "if ... then (if)" b
if [[ ${1:condition} ]]; then
    ${0:${VISUAL}}
fi
endsnippet

Without ${VISUAL} :

snippet if "if ... then (if)" b
if [[ ${1:condition} ]]; then
    ${0}
fi
endsnippet
1
  • 1
    It's to be used with a visual selection. BTW, it would be good to mention which plugins you are using (in this case, Ultisnips)
    – husB
    Commented Nov 5, 2022 at 5:39

1 Answer 1

5

From :h UltiSnips-visual-placeholder,

Snippets can contain a special placeholder called ${VISUAL}. The ${VISUAL} variable is expanded with the text selected just prior to expanding the snippet.

To illustrate with your snippet above with ${VISUAL}, a use case would be to surround a block of code with if ... fi. To do so, first visually select the block of code. Then hit <tab>, followed by if<tab>. The result is

if [[ |condition| ]]; then
    block of code
fi

where condition is now selected.

Without ${VISUAL}, the block of code would be missing:

if [[ |condition| ]]; then

fi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.