Yasnippet has a function called yas-choose-value which is used like this:

<div align="${2:$$(yas-choose-value '("right" "center" "left"))}">

How can I automatically exit the snippet and move to $0 after pressing the return key when making the selection from the choices?

1 Answer 1


For the example in your question, you don't need a to make field, using a backquoted expression should suffice:

<div align="`(yas-choose-value '("right" "center" "left"))`">

This doesn't cover the case where you might want to interact normally with some other fields first though. For that, the new yas-auto-next macro introduced just recently can be used, borrowing the example from the docs:

<div align="${2:$$(yas-auto-next
                      '("right" "center" "left")))}">

Which does the same as above, but will participate with any other fields you add in the normal order.

  • Whenever you have some free time, it would be helpful if your answer could reference issue 937 that implements this new feature.
    – lawlist
    Commented Jun 6, 2018 at 22:05
  • @lawlist, oh right, I had forgotten about this when I pushed that. Edited.
    – npostavs
    Commented Jun 6, 2018 at 22:54

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.