A %sh{} block captures the stderr and stdout of the shell process, so it waits for the shell process to close its pipes before it continues. In bash, you can run:
(sleep 5; echo hello) &
…and five seconds later, “hello” will blurt out in the middle of whatever you’re doing - even though the subshell is in the background, it’s still connected to the existing stdout. The way around this is to redirect the output pipes as well as run the process in the background:
Now the child process is isolated from the parent process, and Kakoune won’t hang waiting for it to finish.
Note: You might wonder why the above example applies & in one set of brackets, then applies the redirections with another, instead of doing them all at the same time. This works around a bug in OpenBSD’s shell.
i don’t expect this to appear in kakoune as is, as it completely eats up output, without offering option to send it to a file or to redirect to some other fd, but it shouldn’t be too hard to write a custom kakoune command for it