The ability to group actions so that they can be undone as a unit is an important one for some plugins that change text “behind the scenes.” This can be done in Insert mode with <c-u>, but I did not know how to accomplish this in Normal mode or in scripts, so I raised the issue as a Feature Request on Github:
It turns out that no special grouping command is needed. As Screwtapello pointed out:
If you put commands inside an evaluate-commands block, that effectively puts them in an undo group together.
This command produces two operations that can be undone individually:
kak -n -e 'exec x~; exec jx~'
This command produces one operation that can only be undone as a unit:
kak -n -e 'eval %{ exec x~; exec jx~; }'
This command also produces one operation that can only be undone as a unit:
kak -n -e 'exec x~jx~'
[I edited Screwtapello’s `exec-commands`, which I think is a typo, into `evaluate-commands`.]
Thought this information could be useful in this forum