xremap: Is there a way to listen for the second keystroke with timeout?

Hello,

I would like to implement something that’s similiar to how key mappings are handled in vim.

say for example I want to remap jk to escape instead of pressing jk all at once I can press j first then I have a short amount of milliseconds to follow with k

is there a way to implement this using Xremap? and if yes can I control the timeout too? If the second key isn’t presessed within the given timeout, that should cancel the listening thank you.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 35 (19 by maintainers)

Most upvoted comments

Thank you for the kind comment. To show my appreciation for you being my GitHub Sponsor, I filed #82.

This issue has not fully explained what’s the expected behavior, so this is an implementation of my random guess. Please leave a comment to the pull request with a config you’d like to use and explain the expected behavior using the format of #82 (comment) if it doesn’t work as expected.

I see that… thank you ask well. Most of your new stars probably came from Reddit ; )

I’ve been trying to publicize this repo because I think it’s accomplishing incredible things that have apparently been too difficult to accomplish for the Linux community. Namely making a powerful yet simple to use keymapper. Options exist fulfilling one, but not both. I am anxiously awaiting this feature and predict, STRONG adoption of xremap if it gets enough exposure

Sorry, I probably confused you by using the wrong word. I just wanted to see a working logic that keeps backward compatibility (your code didn’t) and achieves what you want, and then I would rewrite that to Rust.

Anyway, please just wait until May. Your further action is not needed.

we can make timeout_millis disabled by default, so that you can enable it once you need it.

when it comes to implementation, I think if you make it work as a listener who would listen for an X amount of time, cancel if there’s no response and act if there’s a response within timeout_millis.

I think a reccursive solution to the problem would be best, because if the key squence is more than two keystrokes things might get complicated.

  • timeout_millis must reset to its initial value if there’s another keystroke that we should wait for.
  • the sequence should get cancelled if the user don’t respond, no matter how deep we’re in.

however, it is such a powerful mapping system and I don’t see it implemented anywhere else other than vim and emacs … it enables us to make meaningful shortcuts, with verbs like ciw ==> change inside word

so fast to type, and it eliminates the need for ctrl, shift and all of those akward keys.

the second snippet doesnt’ work because timeout_millis isn’t recognized!

Did you read what I commented? I said “we could possibly extend this”. That doesn’t exist yet and I’m asking whether you want that or not. Could you please just answer Yes or No to what I asked?

  • input: j → 500ms+ wait → k
    • output: 500ms+ wait → j → k
  • input: j → 500ms- wait → k
    • output: 500ms- wait → escape

Is this what you want?