6

Is it possible to create mappings or macros based on keydown and keyup events?

For example, if you press i you enter insert mode, and if you press esc you leave insert mode and enter normal mode.

Could you make it so that if you pressed down i you entered insert mode, and when you released it, you left insert mode?

(not that you would want to do that, I am just giving it as an example of behavior)

  • 1
    Something "similar" is possible either at OS level, or with special firmware in certain mechanical keyboards (I'm thinking at Hasu's TMK). For example, you can then map Caps Lock to act as ESC if pressed and released alone, but to act as CTRL instead, if another key is pressed before Caps Lock release. – VanLaser Mar 23 '16 at 22:22
7

Short answer is no.

Keys are registered as raw I/O; there's no concept of keyup/down/press like you'd find in javascript

Rather vim thinks of input in terms of its modes. You have quite a bit of flexibility when creating bindings for different modes.

:nmap - Display normal mode maps

:imap - Display insert mode maps

:vmap - Display visual and select mode maps

:smap - Display select mode maps

:xmap - Display visual mode maps

:cmap - Display command-line mode maps

:omap - Display operator pending mode maps

note: In neovim there is an additional mode; terminal mode which has its own set of mappings

  • if the answer is sufficient can you accept it? If you have additional questions just let me know and ill do my best to update the answer – Dan Bradbury Mar 24 '16 at 16:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.