I'm curious if it's possible to define a yasnippet completion field with a default value specified to initially edit/modify the value rather than replace it. For this elementary example:


On completion when the point is at the beginning of the field anything typed will replace the value.


Moving the point allows modification of the default value:


(For those about to check, moving it back results in the former behavior):


I'm hoping to retain this observed behavior in general, but be able to change the behavior in an individual field. So that this snippet (with some modification to the snippet definition of the second field) would yield the below behavior.

${1:thing} ${2:else}

ATabBA Belse

This is just a minimal example. It would make sense in this case to simply move the default value outside the field like ${1:thing} $2else), but doing so doesn't allow modification of that value during completion.

Once part of the contents of a field has been modified it is possible to modify from the beginning of that field. I'm thinking this is the hack that is going to be necessary.



The desired behavior would be


  • 1
    I've been playing with this for a bit but I've only found a way to do this that allows the cursor to come after all of the text. Here is the code: test ${1:$$(unless yas-modified-p (concat yas-text "mytext"))}. Hopefully this will help
    – Jules
    Commented Mar 8, 2016 at 22:02


Your Answer

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

Browse other questions tagged or ask your own question.