There’s a plugin for Vim, and many plugins for Emacs that do this kind of thing. I did this via fzf.kak through skim, but I’ve thought that it would be nice to have such grep without plugins:
define-command -override -docstring "flygrep: run grep on every key" \
flygrep %{
edit -scratch *grep*
prompt "flygrep: " -on-change %{
flygrep-call-grep %val{text}
} nop
}
define-command -override flygrep-call-grep -params 1 %{ evaluate-commands %sh{
length=$(printf "%s" "$1" | wc -m)
[ -z "${1##*&*}" ] && text=$(printf "%s\n" "$1" | sed "s/&/&&/g") || text="$1"
if [ ${length:-0} -gt 2 ]; then
printf "%s\n" "info"
printf "%s\n" "evaluate-commands %&grep '$text'&"
else
printf "%s\n" "info -title flygrep %{$((3-${length:-0})) more chars}"
fi
}}
It reuses original Kakoune grep
command in order to do the search. Most of the code here is just escaping, and counting chars. As result, this command allows you type the pattern and search for it in semi-realtime