When expanding a yasnippet snippet and filling out completion fields yanking/pasting inserts text correctly among fields as expected, but interrupts the snippet expansion behavior (as if pressing C-g / calling yas-abort-snippet).

How can I yank content and continue with yasnippet expansion?

Edit: This appears to be a problem with yasnippet itself and the order of placeholder fields. According to the documentation I believe each of these forms are correct and should work.

Since this is exceptional behavior and not universally broken yanking:

Are these forms valid / Is this in fact a bug?

This works:

# -*- mode: snippet; require-final-newline: nil -*-
# name: work
# key: work_
# binding: direct-keybinding
# --
This works: ${1:someDefault}

This doesn't:

# -*- mode: snippet; require-final-newline: nil -*-
# name: nowork
# key: nowork_
# binding: direct-keybinding
# --
This does not work: $1

(emacs 24.5.1; yasnippet version 20160104.129)

  • 1
    Could you post an example snippet where this problem is occurring, and briefly walk through what happens? I can't recreate the behaviour you are describing. For me, yanking does not interrupt snippet expansion. I am even able to go to another buffer during expansion, kill some text, and then yank it into my expanding snippet in the other buffer before continuing with the expansion.
    – elethan
    Jan 19, 2016 at 15:05
  • Hmm, I am on the same version of emacs and yasnippet as you, and both your examples work for me. What is not working about them for you?
    – elethan
    Jan 19, 2016 at 22:01

1 Answer 1


One thing that you could do (though in the example below, it would limit you to the most recent thing on the kill ring), is to use elisp code embedded in your snippet:

# -*- mode: snippet; require-final-newline: nil -*-
# name: my-snippet
# key: foo
# binding: direct-keybinding
# --
Here is my text to yank: `(yank)`. And here is the rest: $1 $2

When you expand the snippet, the most recent item on your kill-ring will actually be yanked in automatically, saving you the additional step of having to yank it your self.

However, after coming up with this example, I tried yanking as normal with C-y during snippet expansion, and it works fine, i.e., I am able to yank, and then press TAB to move to the next placeholder. I am even able to cycle through the kill-ring and yank older pieces of text without interrupting snippet expansion. If you have not updated yansippet recently, you might try doing that.

  • It would be better to use (current-kill 0) instead of (yank). Using yank modifies the buffer by side-effect which makes it dependent on the particular way in which yasnippet currently performs snippet expansion (see also emacs.stackexchange.com/questions/17044/…)
    – npostavs
    Apr 19, 2016 at 15:57

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.