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
    Commented Mar 23, 2016 at 22:22

1 Answer 1


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 and newer versions of Vim, there is an additional mode; terminal mode, which has its own set of mappings


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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