I think your issue comes from the fact that git creates a new temporary COMMIT_EDITMSG file each time, but you are using BufOpenFile, which triggers when the file already exists.
Taken from :doc hooks :
BufOpenFile filename
a buffer for an existing file has been created
I think the Buf* hooks execute in buffer context, while things like “cursors” and “insert mode” only exist in window context. Instead of trying to enter insert mode immediately, you might like to tell Kakoune to try it once everything’s initialised and it’s ready for editing to begin:
hook global BufOpenFile '.*/COMMIT_EDITMSG$' %{
hook -once buffer NormalIdle .* %{
# Automatically enter insert-mode at end of line.
exec A
}
}
(also, the pattern for the BufOpenFile hook could just be .*/COMMIT_EDITMSG without the $, since Kakoune implicitly wraps every hook pattern with ^ and $)
Only problem I could detect was that it broke my keychord (lh) for exiting insert mode:
# Make it possible to exit insert mode using "lh".
hook global InsertChar l %{
hook -group lh global InsertChar h %{
try %{
exec -draft hH <a-k>lh<ret> d
exec <esc>
}
}
$ sh -c %{
sleep 0.2
:send rmhooks global lh
}
}
Any idea how I can fix that as well?
The keychord works whenever I run Kakoune normally, it just doesn’t work when the hook you provided has been run…
Well, I thought the BufCreate trick worked because it changed my cursor color (I switch to purple when in insert) and did not bother checking more.
This means that exec A does execute, and I’m in insert mode while not being in insert mode ?
I can freely move around while my cursor is clearly indicating insert mode