It’s a bit complicated because (unlike, say, Vim) Kakoune has a client-server architecture. You can create new clients by running :new
inside Kakoune, or by running kak -c SESSIONNAME
(where SESSIONNAME
is the “1234” part of the “client0@[1234]” visible at the right-hand end of Kakoune’s status bar), while the server is started automatically and shuts down when the last client disconnects.
When you press <c-z>
to suspend “Kakoune”, that keystroke is intercepted by the client, which suspends itself rather than sending the keystroke along to the server.
When you put <c-z>
in a mapping, or do :exec <c-z>
, that executes on the server which knows nothing about terminals or which clients might be using them.
As an actual practical solution, I typically have two terminals open - one for Kakoune, and another one to run interactive scripts or tests or browse documentation or whatever.
Alternatively, you could use the :terminal
command to run your script, which launches a new terminal instead of suspending Kakoune inside the current one.
If you don’t mind doing something a bit more hacky, instead of :exec <c-z>
you could do something like:
nop %sh{ kill -TSTP $kak_client_pid }
…which should send the same signal to the current client that <c-z>
normally would. I’m not sure if Kakoune gets an opportunity to do the same cleanup/restore it does with <c-z>
though, so it might make your interactive script a bit glitchy.