I’ve added kakhist to mru-files.kak. It’s a separate module, so those who have their own MRU’s can use kakhist independently (it does, however, require the sh library module in the same repo). There’s also a vim q: replacement which you can map to g: (command history buffer).
kakhist saves & restores command (:) history to/from a single kakhist.txt file. It works with multiple, overlapping sessions without clobbering unrelated histories — it figures out which commands have been loaded and which are new for the session (only new ones are appended to kakhist.txt when the client exits).
Note: if you have have a single kak server for all kak's (single session), you may wish to stick with @Screwtapello’s kakoune-state-save (state-save-reg-save colon). kakhist hands the command history over to the sh, so it can do (by default when kak starts / exits) command filtering and avoid multiple-session clobbering.
Filtering
You can define arbitrary sh code to filter out commands that shouldn’t be saved (option mru_files_ignore_sh). The default code filters out quit-related commands and sets up $2 to contain the base command name, stripped of args and ! ($1 always contains the full command). You can replace it completely, or append to it. To add exclude patterns (e.g. don’t save pwd):
set -add global kakhist_ignore_sh %{
case "$2" in
pwd|w|write) return 0 ;; # reject
esac; false # don't exclude for now
}
Such code can be further appended to. kakhist-save only checks the return code of the last command.
Command history buffer
kakhist-buf-show shows a list of previous commands, like vim’s q:. Press <ret> on any line to execute. I personally map it to “g:”:
map global goto ':' '<esc>: kakhist-buf-show<ret>' \
-docstring 'show command history'
Implementation notes
kakhist-{load,save} add a special marker (: kakhist-save, which should never enter history normally as it begins with a space) to the colon register. kakhist-save appends everything after the last marker to kakhist.txt. This way, different sessions never step on each others’ toes.
To save, the shell script does
eval set -- "$kak_quoted_reg_colon"
… which loads all list elements into sh “$@” positionals. I believe this is the safest approach in general to loading an “array” into shell, e.g.
decl str-list tst
set -add buffer tst 'a "b" c'
set -add buffer tst 1
set -add buffer tst "d 'e' f"
echo -to-file /tmp/tst -quoting shell %opt{tst}
nop %sh{
eval set -- "$(cat /tmp/tst)"
printf 1>&2 ':%s:\n' "$3" "$2" "$1"
}
processes list members as expected.
Extra
I’ve also added persistent session (= currently open buffers) support to mru-files.kak. mru-files-session-save generates a list of edit commands that recreate the current session, in the spirit of vim’s mksession.
If you think this might be useful, please test & enjoy. Comments, suggestions, GitLab issues etc all welcome.



