4

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

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

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

2

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"))`">
  $0
</div>

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
                    (yas-choose-value
                      '("right" "center" "left")))}">
  $0
</div>

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 Jun 6 '18 at 22:05
  • @lawlist, oh right, I had forgotten about this when I pushed that. Edited. – npostavs Jun 6 '18 at 22:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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