Reputation: 43
vscode > Preferences: Open Settings (JSON)
{
"vim.normalModeKeyBindingsNonRecursive": [
{
"before": ["t", "s"],
"commands": ["python.sortImports"],
}
]
}
I set it up as above, but it doesn't work. What could be wrong? I'm typing 't' and 's' in vim-normal mode. ctrl+alt+s is woring. but i wanna have custom vim shortcuts
Upvotes: 4
Views: 4436
Reputation: 52198
For anyone else arriving here from a search for how to get vim keybindings working in vs code, I didn't have to change any vscode settings at all, I simply pressed command + shift + x to open the 'Extensions' tab, searched for 'vim' and installed the top extension (see below). Then vim keybindings worked without any additional steps (didn't even need to restart vscode, which is great).
Upvotes: 0
Reputation: 388
Try reinstalling the vim extension. If this fails, you could try the following:
- Are your configurations correct?
Adjust the extension's logging level to 'debug', restart VS Code. As each > remapped configuration is loaded, it is outputted to console. In the Developer > Tools console, do you see any errors?
debug: Remapper: normalModeKeyBindingsNonRecursive. before=0. after=^. debug: Remapper: insertModeKeyBindings. before=j,j. after=<Esc>. error: Remapper: insertModeKeyBindings. Invalid configuration. Missing 'after' key or 'command'. before=j,k.
Misconfigured configurations are ignored.
- Does the extension handle the keys you are trying to remap?
VSCodeVim explicitly instructs VS Code which key events we care about through > the package.json. If the key you are trying to remap is a key in which vim/vscodevim generally does not handle, then it's most likely that this extension does not receive those key events from VS Code. With logging level adjusted to 'debug', as you press keys, you should see output similar to:
debug: ModeHandler: handling key=A. debug: ModeHandler: handling key=l. debug: ModeHandler: handling key=<BS>. debug: ModeHandler: handling key=<C-a>.
As you press the key that you are trying to remap, do you see it outputted here? If not, it means we don't subscribe to those key events. It is still possible to remap those keys by using VSCode's keybindings.json.
Source: https://marketplace.visualstudio.com/items?itemName=vscodevim.vim#debugging-remappings
Upvotes: 2