Sending one command to edit multiple files

I make a command which is sending from ranger to edit a file in kak.
Command currently is echo "eval -client client0 %%{edit %p}" | kak -p session and it works well.

Ranger’s placeholder %p contains multiple file paths separated by space, but kak’s command edit accept only one, so if i select in ranger many files and send the command to kak it opens only last.

How to improve command sending to edit all the files in %p?

While echo just produces one output, printf keeps producing copies of its format string until all the arguments have been consumed:

$ echo 1 2 3
1 2 3
$ printf "hello %s\n" 1 2 3
hello 1
hello 2
hello 3

So if we use printf, we should be able to construct multiple commands and send them all to the same Kakoune instance:

printf "eval -client client0 %%{edit %s}" %p | kak -p session

As a bonus, you might be interested in tools like, kakoune-remote-control, or kks, which should let you launch a terminal from within Kakoune, and then inside that terminal there will be commands that automatically connect back to the original Kakoune instance, instead of you having to hard-code client0 and session in your ranger command.

Thx for printf and pointing to the tools.

Leave if for those who uses ranger, full command is map <a-enter> shell -s printf "eval -client client0 %%%%{edit %%s\n}" %p | kak -p coding. A lot of escape symbols as you see, some of them are ranger’s ones, some printf’s.