Key Bindings
Onivim's keyboard configuration is designed to be mostly compatible with VSCode's Key Bindings.
Editing the keybindings
- Press
Command+Shift+P
(Mac) orControl+Shift+P
(Windows, Linux) to bring up the command palette - Select
Preferences: Open keybindings File
Keybinding Format
Keybindings are defined as a JSON array, like:
[
{ "key": "<C-P>", "command": "workbench.action.quickOpen", "when": "editorTextFocus" }
]
Each rule consists of:
- A
key
that describes the pressed keys
NOTE: Today, our key format is expressed as a Vim-style key-binding. Our plan, though, is to support both Vim-style (
<C-K>
) and VSCode-style key specifies (ctrl+k
)
- A
command
containing the identifier of the command to execute - An optional
when
clause containing a boolean expression that will be evaluated depending on the current editor state.
When a key is pressed:
- The rules are evaluated from bottom to top
- The first rule that matches, both the
key
and in terms ofwhen
is accepted - If a rule is found and has a
command
set, thecommand
is executed. - If no matching rules are found, we pass the input key through to
libvim
to be handled by Vim.
There are a set of default rules provided by Onivim, but the customized rules are appended to the bottom - thus, user key bindings are executed first.
key
format
The key
parameter supports both Vim style and VSCode style key bindings.
Remaps
Remaps can also be specified via the same keybindings configuration file.
Remapping keys tend to be more natural for users coming from Vim, and they allow matching a key sequence and then producing a new set of key presses.
Remaps require 3 properties:
from
- a key, specified in the same format as thekey
parameterto
- a key, specified in the same format as thekey
parameterwhen
- a context clause describing when the remapping should take effect.
An example of a remap would be:
{ "from": "jj", "to": "<esc>", "when": "editorTextFocus && insertMode" }
(which is functionally equivalent to :inoremap jj <ESC>
)
Vim style
Vim-style keybindings are surrounded by <
and >
, and allow the following modifiers:
Modifier | Description | Example |
---|---|---|
C- | Control key | <C-P> |
S- | Shift key | <S-P> |
A- | Alt key | <A-P> |
D- | Command key | <D-P> |
Note: A difference between Vim and Onivim is that
D-
also handles the 'Meta' and 'Win' keys on Linux and Windows, respectively
Modifiers may be combined, for example:
[
{ "key": "<C-S-P>", "command": "workbench.action.quickOpen", "when": "editorTextFocus" }
]
The <C-S-P>
key binding would require the Control, Shift, and P keys to be pressed.
VSCode style
VSCode-style keybindings feature friendly names, like:
Modifier | Description | Example |
---|---|---|
Ctrl+ | Control key | Ctrl+P |
Shift+ | Shift key | Shift+P |
Alt+ | Alt key | Alt+J |
Meta+ | Meta/Command/Windows key | |
Cmd+ | Same as above | Cmd+P |
Win+ | Same as above | Win+P |
Key Sequences
Onivim supports binding to key sequences, which require multiple key-presses in succession to engage.
Example:
{ "key": "jk", "command": "vim.esc", "when": "insertMode" }
This would require a key-press of 'j', followed by 'k'.
command
arguments
when
clause contexts
Onivim 2 gives you control over when key bindings are enabled through the when
clause.
Conditional operators
For conditional expressions, you can use the following conditional operators:
Operator | Symbol | Example |
---|---|---|
Or | || | listFocus || textInputFocus |
And | && | insertMode && suggestWidgetVisible |
Expressions may be grouped with ()
, for example:
(editorTextFocus && !insertMode) || suggestWidgetVisible
Contexts
Common contexts with VSCode:
Context Name | True When |
---|---|
editorFocus | An editor has focus |
editorTextFocus | An editor has focus |
hasSearchResults | Search results are available |
inSnippetMode | A snippet session is currently active |
renameInputVisible | The rename input is visible |
suggestWidgetVisible | The suggest widget (auto-completion) is visible |
textInputFocus | A text input area has focus |
terminalFocus | A terminal has focus |
The activeViewlet
context key corresponds to the id of the open sidebar pane:
workbench.view.explorer
- File Explorerworkbench.view.extensions
- Extensionsworkbench.view.scm
- SCMworkbench.view.search
- Search
The editorLangId
context key corresponds to the language identifier of the active editor (the same value shown in the statusbar), and can be combined with other context keys, like:
'when': 'editorFocus && editorLangId == typescript'
Onivim-specific contexts:
Context Name | True When |
---|---|
insertMode | The active editor is in insert mode |
normalMode | The active editor is in normal mode |
visualMode | The active editor is in visual mode |
sneakMode | Sneak mode is active |
commandLineFocus | The Vim commandline is open |
listFocus | A list of items (like a pop-up menu) is focused |
sideBarFocus | The sidebar has focus visible |
sideBarVisible | The sidebar is visible |
paneFocus | The bottom pane has focus |
vimListNavigation | Inside a Vim-navigable list |
vimTreeNavigation | Inside the file explorer |
Commands
Default Key Binding | Description | Command |
---|---|---|
Command+Shift+P / Control+Shift+P | Show Command Palette | workbench.action.showCommands |
Command+Shift+M / Control+Shift+M | Show Problems Pane | workbench.actions.view.problems |
Command+P / Control+P | Quick Open (File Picker) | workbench.action.quickOpen |
Control+Tab | Navigate to next editor in group | workbench.action.quickOpenNavigateNextInEditorPicker |
Shift+Control+Tab | Navigate to previous editor in group | workbench.action.quickOpenNavigatePreviousInEditorPicker |
Command+PageDown | Navigate to next tab | workbench.action.nextEditor |
Command+PageUp | Navigate to previous tab | workbench.action.previousEditor |
Command+= / Control+= | Zoom In | workbench.action.zoomIn |
Command+- / Control+- | Zoom Out | workbench.action.zoomOut |
Command+0 / Control+0 | Zoom Reset | workbench.action.zoomReset |
Basic Editing
Default Key Binding | Description | Command |
---|---|---|
Control+V / Command+V | Paste from clipboard | editor.action.clipboardPasteAction |
Control+S / Command+S | Save file | workbench.action.files.save |
Language Features
Default Key Binding | Description | Command |
---|---|---|
F2 | Rename | editor.action.rename |
F12 or gd | Go-to Definition | editor.action.revealDefinition |
Shift+F12 | Go-to References | editor.action.goToReferences |
List / Menu commands
NOTE: Some of the list select commands may not be fully hooked up yet, such that they may not respect vertical/horizontal opening.
Default Key Binding | Description | Command |
---|---|---|
Up Arrow / Control+P | Move focus up | list.focusUp |
Down Arrow / Control+N | Move focus down | list.focusDown |
Enter | Select current item | list.select |
Shift-Enter | Select current item (vertical open) | oni.list.selectVertical |
Ctrl-x | Select current item (horizontal open) | oni.list.selectHorizontal |
Ctrl-t | Select current item (new tab) | oni.list.selectNewTab |
Search Pane
Default Key Binding | Description | Command |
---|---|---|
F4 | Focus next search result | search.action.focusNextSearchResult |
Shift+F4 | Focus previous search result | search.action.focusPreviousSearchResult |
Sidebar
Default Key Binding | Description | Command |
---|---|---|
Command+Shift+E / Control+Shift+E | Focus Explorer | workbench.view.explorer |
Command+Shift+F / Control+Shift+F | Focus Search | workbench.action.findInFiles |
Command+Shift+X / Control+Shift+X | Focus Extensions | workbench.view.extensions |
Control+Shift+G | Focus Source Control | workbench.view.scm |
Control+W, Control+J | Navigate down a section | vim.window.moveDown |
Control+W, Control+K | Navigate up a section | vim.window.moveUp |
Snippets
Default Key Binding | Description | Command |
---|---|---|
n/a | Insert a Snippet | editor.action.insertSnippet |
n/a | Configure user snippets | workbench.action.openSnippets |
Window Management
Default Key Binding | Description | Command | |
---|---|---|---|
Control+W, Control+V | Vertical Split | view.splitVertical | |
Control+W, Control+S | Horizontal Split | view.splitHorizontal | |
Control+W, Control+H | Move to left split | window.moveLeft | |
Control+W, Control+L | Move to right split | window.moveRight | |
Control+W, Control+J | Move down a split | window.moveDown | |
Control+W, Control+K | Move up a split | window.moveUp | |
Control+W, Control+R | Rotate forwards | view.rotateForward | |
Rotate backwards | view.rotateBackward | ||
Decrease editor size | workbench.action.decreaseViewSize | ||
Increase editor size | workbench.action.increaseViewSize | ||
Decrease editor size horizontally | vim.decreaseHorizontalWindowSize | ||
Increase editor size horizontally | vim.increaseHorizontalWindowSize | ||
Control+W, - | Decrease editor size vertically | vim.decreaseVerticalWindowSize | |
Increase editor size vertically | vim.increaseVerticalWindowSize | ||
Decrease editor size up | vim.decreaseWindowSizeUp | ||
Increase editor size up | vim.increaseWindowSizeUo | ||
Decrease editor size down | vim.decreaseWindowSizeDown | ||
Increase editor size down | vim.increaseWindowSizeDown | ||
Decrease editor size left | vim.decreaseWindowSizeLeft | ||
Increase editor size left | vim.increaseWindowSizeLeft | ||
Decrease editor size right | vim.decreaseWindowSizeRight | ||
Increase editor size right | vim.increaseWindowSizeRight | ||
Control+W, O | Maximize editor | workbench.action.maximizeEditor | |
~~Control+W, \ | ~~ | Maximize editor horizontally | vim.maximizeWindowWidth |
Maximize editor vertically | vim.maximizeWindowHeight | ||
Toggle editor group sizes | workbench.action.toggleEditorWidths | ||
Control+W, = | Reset editor sizes | workbench.action.evenEditorWidths |
Vim commands
Default Key Binding | Description | Command |
---|---|---|
Escape | Used to send <ESC> to Vim | vim.esc |
Additional Commands
Default Key Binding | Description | Command |
---|---|---|
n/a | Enable KeyDisplayer | keyDisplayer.enable |
n/a | Disable KeyDisplayer | keyDisplayer.disable |
Ex Commands
Commands that start with a :
(colon) will be interpreted as vim ex commands. These can also carry arguments.
Examples:
{"key": "kk", "command": ":split", "when": "editorTextFocus"},
{"key": "<C-D>", "command": ":d 2", "when": "insertMode"}
Leader Key
A leader key can be specified via the following configuration setting:
{ "vim.leader": "<space>" }
NOTE: This setting is in
configuration.json
, notkeybindings.json
Alternatively, the leader key can be specified via an Ex
command:
:nmap <space> <Leader>
Once the leader key is defined, it may be used in both keybindings.json
and via VimL map commands:
[
{ "key": "<Leader>p", "command": "workbench.action.quickOpen", "when": "editorTextFocus && normalMode" }
]
or, alternatively, in VimL:
:nnoremap <Leader>p <C-S-P>