Modal Keybindings in VS Code
ModalKeys is an extension for defining modal keybindings in VSCode. Vim is probably the most well known modal
and ModalKeys includes
that resemble Vim.
The above is a screenshot of the visual documentation feature of this extension; you can access this feature using the command
ModalKeys: Toggle keymap documentation, or
ModalKeys: Show keymap documentation. It documents the current effect of pressing any given key in the current keymode; the display will update as needed for multi-key commands.
The advantages of modal bindings are the rapid, speed-of-thought manipulations you can perform on text with a well-designed keymap and sufficient practice.
The advantages of using ModalKeys specifically include:
- Visual documentation of all keybindings
- Seamless integration with the existing features and
extensions of VSCode
- Complete customization. While you can
emulate many of the features of other modal editors like Vim or
Kakoune, you will get the
most out of ModalKeys by creating your own keymap or modifying an existing one (e.g. starting with one of the
To start creating a custom set of keybindings for ModalKeys, you have a few options:
- Read the Tutorial
- Start with an example from presets, using the export and import commands to create and then use your own version of the presets.
- Read through the Documentation
The general phillosphy of ModalKeys is to leverage existing functionality and behavior already available from VSCode and its extensions, and make it easy to define modal key bindings for these behaviors. If you don't care to integrate behavior from across VSCode and its extensions, you probably just want to replicate an existing modal editor in VSCode; in this case you may want to consider using VSCodeVim,
vscode-neovim, or Dance.
ModalKeys is a fork of ModalEdit;
I am in debt to the hard and thoughtful work from that extension along with its
meticulous documentation. There are many important features that differ between
the two extensions.
What follows are are just some of the features ModalKeys has which ModalEdit lacks.
- Concise keymap format: I've created a terser, simplified keymap format
- Visual documentation: you can fill out
::doc:: entries and these will populate a visual keymap documenting your keybindings
- Customized modes: You can define your own key modes, to expand the keymap more easily
- Search term highlighting: ModalKeys highlights search terms by default (there is an open PR in ModalEdit)
- Search with regex: The
search command can optionally use regex expressions
- Kakoune-like 'repeat-selection': ModalKeys provides a
repeatLastUsedSelection command to make kakoune noun-verb workflows repeatable (in contrast with vim's verb-noun workflows)
- Keyboard macros
ModalKeys is missing a few features I did not want to maintain from ModalEdit: bookmarks and quick snippets. I find these features to be well covered by several existing extensions in VSCode.