Hi, folks. I’d like to insert the content from a file after the current selection, similar to vim’s :read command. How does one do this in Kakoune? I tried a few dozen keywords and didn’t find anything in the existing documentation.
Thank you! I tried to use the ! keystroke (" insert command output before selection"), but that didn’t do what I expected. Do you know what it does that differs from what you offered here? I expected this to work:
Coming back into Kakoune, what exactly would be the way to abstract the use of <a-!> here into a command? Because execute-keys <a-!>cat %arg{1}<ret> won’t work, will it?
# https://neovim.io/doc/user/insert.html#:read
define-command read -params 1.. -docstring 'Insert the file [name...] below the cursor' %{
# Execute the commands in a temporary context,
# where the registers will be restored.
evaluate-commands -save-regs 'a|' %{
# Store arguments into the `a` register.
set-register a %arg{@}
# Set the shell command to concatenate the files.
set-register | %{
# Set the arg-list with the `a` register.
eval "set -- $kak_quoted_reg_a"
# Concatenate the files.
cat "$@"
}
# Paste the output of the shell command.
execute-keys '<a-!>' '<ret>'
}
}
I feel like it might be necessary to abstract ! or <a-!>[some commandline command] as a…well “function,” but you get what I mean, in these cases. Because there might be other commands one might want to insert or append the output of. I think using %sh{} would get even messier, maybe.
The eval -- "%%EXPANSION{%arg{1}}" trick is awesome — with %file, %sh{}, %opt{}. The only problem is that the content inside %EXPANSION{} must balance braces (and in correct order too).
For %file, I would recommend eval -- reg dquote "%%file<%arg{1}>" — and then the filename needs to balance angular brackets instead. Those are unlikely to appear in filenames.