Interactively use kak -f for scripting

Kakoune is not just an awesome text editor, it’s often a great replacment for sed and friends in scripts. To find to right expression for my scripts I use the following snippet:

cat some_file.txt | xclip -f | fzf --phony \
    --read0 \
    --print0 \
    --sync \
    --ansi \
    --preview 'xclip -o | kak -f '{q}'' \
    --preview-window 'up:99%' \
    --bind 'enter:print-query'

It feels very much like using kakoune as normal text editor but spits out the keys you need for the script instead of the modified text. If you modify it slightly it can be used with other tools like jq, sed, awk, etc too (in fact, that’s how I found it).

Hope this is as useful for you guys as it is for me.

It would be even better if there was some kind of -ansi cli-flag for kakoune. Than one could even see the selections interactively and later use the keys in the script without the -ansi flag.


You can probably achieve something similar by starting a new kakoune session with a macro recording started and dumping the contents of the macro register to a file. Would be a little more interactive.