Open nitish-17 opened 2 years ago
I guess the solution would be when the next key doesn't match the keybind, instead of inserting it you check again to see if it's the start of another key combination?
That might work but I like the current system where a key not found in a pending key sequence cancels the sequence (see here).
Kakoune has an interesting way of approaching this: https://github.com/mawww/kakoune/wiki/Avoid-the-escape-key#jk-to-escape. It maps k
to a hook that deletes the preceeding jk
sequence if it exists, and if it existed it goes to normal mode. I don't think we can create a similar keybinding without scripting support for config though.
In vim, this type of exiting insert mode has a timeout. So, while there's a short (but configurable) inconvenience if you want to end your insertion on 'j', it's at least possible. I was a bit surprised to find that helix's helpful little keymap sequence hint window just persists indefinitely, waiting for the next key.
fwiw, this is my first day with helix and I am truly delighted so far.
This was the first (and only major) problem I've hit with Helix so far.
Wonder if anyone has viable solutions for it? If the text your editing in insert mode ends with the first letter of your jj/jk/fd/kj/whatever, what do you do?
E.g., I have f-d
as exit-to-normal-mode sequence.
buffd
in vim would result in buf
whereas in Helix it results in buffd
.j-k
doesn't help either (since on the first f
you will already enter the sequence mode and j
will just cancel it).Esc
which is not nice.Glad to not be the only one with this issue. I use jj
to escape insert mode. On VIM there is a timeout implemented for these kind of commands. If I press j
once, it waits for a couple of seconds. After the timeout is done, j
is inserted in the document. If I press another key (not bound to j
) then j
and the new key are inserted.
The key bound to the command get inserted in the document but if the next key executes a command then that key is removed and the command executed
Previously, I used Neovim to use kj
to exit insert mode, but in the past few days with Helix, I have become very accustomed to using C-[
to exit insert mode.
Have you tried nested binding like this?
[keys.insert] #ā
'j' = {f='normal_mode','j'={'f'=[':insert-output /bin/echo -n j','move_char_right','normal_mode']}}
# 'hij' + 'jf' cleanly exits after typing 'hij' instead of typing an extra jf
# the char movement was needed because otherwise you end up 1 char left with insert and with append-output at the end of the line you get an insert at the wrong line
(though this is missing a proper text insertion API, check https://github.com/helix-editor/helix/issues/2797)
@zeeklop
it waits for a couple of seconds
that's also bad
The proper way to do this type of switching is like this:
(as implemented in https://github.com/NeoVintageous/NeoVintageous)
See this short demo
https://github.com/helix-editor/helix/assets/12956286/d07fc374-9d5f-47ec-ac6d-3f663351f11d
Although an even better solution would be to have an on-hold functionality since you'd not use that in regular typing, so you don't have this conflict in the first place, then you could have a clean
ij
is tracking key releases, if j is released first, then it's was a (hold)i, otherwise it's just a regular typing sequence where the earlier typed key is always released earlier)just like you can have the same with other modes
(though this suggestion was unfortunately shot down https://github.com/helix-editor/helix/issues/1494)
Another workaround is to use a good keyboard remapping tool (like Karabiner on a Mac) to implement the workaround I use for the lack of on-hold functionality: basically, make some key like i
i
on release instead of on pressHowever, this is limited by:
(you can also do it for a key chord like jf, but I think it's more bug-prone due to the aforementioned limitations)
Mac example: Helix config
[keys.insert] #ā
'A-}' = 'normal_mode' # some unused inconvenient shortcut, ideally free in any mode
Goku Karabiner config snippet
:applications {:wezterm ["^com\\.github\\.wez\\.wezterm$"]}
:main [
{:des " š æiā£ ā¶ Normal Mode ā§ā] (@WezTerm instead of @Helix)" :rules [:wezterm
[:i nil nil
{:alone {:key :i :halt true} :delayed{:canceled[:i]} :held{:key :ā§āć :repeat false}
:params{:alone 254 :held 255 :delay 255} }]
]}
]
Is there any opposition from the maintainers to having proper support for this? It's a dealbreaker for me to use Helix, but I'm happy to try to implement it if it's desired.
Summary
I'm using
jf
to exit insert mode. When I insert anything that ends withj
(notjj
) and try to exit insert mode withjf
I end up insertingjf
and remain ininsert
mode. To overcome this I usually end up pressing escape key twice to exit insert mode which is not ideal.Reproduction Steps
context: I'm using
jf
to exit insert mode.I tried this:
hij
and exit insert mode withjf
I expected this to happen:
hij
and end up in normal modeInstead, this happened:
hijjf
and end up ininsert
modeHelix log
No response
Platform
Linux
Terminal Emulator
gnome terminal
Helix Version
helix 22.03 (d4e45fd4)