Log my normal mode keystroke

Hello,

Is there a way to log all the key I press in normal mode ?

The goal is to analyze the key frequency and optimism my normal mode mapping.

I believe you could use the hooks ModeChange and RawKey.

1 Like

I tryed the following:


hook buffer -always RawKey . %{
    on-key %{
        nop %sh{ notify-send "$kak_key" }
        execute-keys -with-hooks -with-maps %val{key}
    }
}

But it does’t record all keystrokes and break a few functionality ( regarding selection for e.g )

While a mapping is executed instead of the normal processing of the given key, a hook is executed in addition. So your hook doesn’t need to “pass the key along” with execute-keys, that’ll happen automatically.

Also, your hook pattern is . which will match keys like a or |, but won’t match keys whose name is more than a single character, like <a-i> or <lt>.

Try changing your hook to:

hook buffer -always RawKey .* %{
    nop %sh{ notify-send "$kak_key" }
}

Thanks ! yes .* is better.

But I think I need to use on-key to be able to use $kak_key:
executing: hook buffer -once RawKey .* %{ echo %val{key} }
return the following error ( in *debug* ):
error running hook RawKey(j)/: no such env var: key

And on-key is executed instead the normal processing of the given key so you need the execute-keys

Oh, right. Hooks provide the hook_param expansion, not key:

hook buffer -always RawKey .* %{
    nop %sh{ notify-send "$kak_hook_param" }
}
1 Like

AAAAhh awesome $kak_hook_param was exactly what I was looking for !

I didn’t manage to find it in the :doc tho

Thanks

You may want to have a look to (now gone), vim croquet page https://web.archive.org/web/20190404225629/https://www.drbunsen.org/vim-croquet/

2 Likes