Vim
Vim copied to clipboard
Use `when` clause in keybinding overrides
I would love to use something like this:
"vim.insertModeKeyBindings": [
{
"before": ["ctrl", "p"],
"after": [],
"commands": [
{
"command": "editor.action.triggerSuggest",
"when": "editorHasCompletionItemProvider && editorTextFocus && !editorReadonly && !suggestWidgetVisible"
},
{
"command": "selectPrevSuggestion",
"when": "editorTextFocus && suggestWidgetVisible"
}
]
},
{
"before": ["ctrl", "n"],
"after": [],
"commands": [
{
"command": "editor.action.triggerSuggest",
"when": "editorHasCompletionItemProvider && editorTextFocus && !editorReadonly && !suggestWidgetVisible"
},
{
"command": "selectNextSuggestion",
"when": "editorTextFocus && suggestWidgetVisible"
}
]
}
]
Use-case
Demonstrates behavior of Ctrl + P
in normal and insert modes.
Normal mode
Works without change - lets me find and open a file in a project.
Insert mode
When I do not have suggestion window visible, it will trigger the suggestion window to be visible.
When I do have suggestion window visible, it will go to previous suggestion.
This is a very reasonable request.
I was thinking about the same thing that users might just want to map their familiar keybindings to Code's commands. Right now you can't always make it happen with Code's keybinding customization.
- You can't map
j j
to a command in Code while it's possible in VimxyzModeKeyBindings
. - You want to map keys on in a specific Vim mode.
The only catch is the when
clause is not possible as we don't have access the context of keybindings.
Albeit a valid feature ask. This issue hasn't received a lot of traction in terms of upvotes, and we are missing the necessary API from VS Code to implement such a feature. As such, I'm closing this to keep our issue list more sane.
I want to :nmap ]l <f4>
(like unimpaired.vim), but it is impossible without when clause.
Instead of using VSCodeVim's keybinding, I put them in keybindings.json
then append && editorTextFocus && vim.mode == 'Normal'
to when clause.
{
"key": "] l",
"command": "goToNextReference",
"when": "referenceSearchVisible && editorTextFocus && vim.mode == 'Normal'"
},
It might not always work, but for my case this worked.
With above method when typing r ]
in normal mode VSCode swallows ]
and waiting for second key of chord... 🤔
To workaround, can we have context that represents whether VSCodeVim is waiting for second key?
"when": "referenceSearchVisible && editorTextFocus && vim.mode == 'Normal' && !vim.waitingForKey"
Got hit with this problem too. Something like vim.waitingForKey
would be a blessing.