Yank and pasting inside a command


I can’t manage to copy and inside the following command:

define-command create-snippets -docstring %{
'create a snippets from selection'
} %{
    execute-keys y # yank my selection
    prompt -file-completion 'enter snip name' %{
        edit "~/src/snippets/snippets/%opt{filetype}/%val{text}"
        execute-keys p # doesn't past my selection yanked 3 lines above


I solved it using register ( "oy and "op ) but I’m curious to know why register are needed and it doesn’t work with the default register

From execeval.asciidoc:

execute-keys also save the following registers, who are then restored when the commands have been executed: /, ", |, ^, @.

When you say execute-keys y:

  • Kakoune saves (among other things) the current value of the default yank register (the ") register
  • Kakoune yanks the current selection into the " register
  • execute-keys has executed its last key, so it restores (among other things) the original value of the " register.

You can get around this by using the -save-regs '' switch to execute-keys (that is, passing an empty string as the list of register names to be saved). Note that this clobbers the global " register every time somebody calls :create-snippets.

1 Like