Support context for keybindings
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 15.2k
- Forks
- 1.5k
- Avg merge
- 3d 18h
- Merged PRs (30d)
- 6
Description
In regular vim I bind the same key to different tools depending on the language currently open.
For example, binding 't' to run pytest in python, or go tests when editing golang.
In vim I use a different au command based on the file or buffer language type to map the keys.
In vscode's keybindings.json they have the concept of 'context' , so maybe something like this would work:
"vim.normalModeKeyBindings": [
{
"before": ["<leader>", "r"],
"commands": ["python.datascience.runFileInteractive"],
"when": "editorLangId == python && editorTextFocus"
},
{
"before": ["T"],
"commands": ["test-explorer.run-all"],
"when": "editorTextFocus"
},
{
"before": ["T"],
"commands": ["go.test.all"],
"when": "editorTextFocus && editorLangId == go"
}
]
in this example, the only when editing a python file would the IDE try and run file in jupyter.
Similarly, the Go language's test plugin doesn't work with Test Explorer, but Java and Python do - so when editing go files call the appropriate plugin method.
Idea 2
Another way to get this behavior might be to leverage VSCode's own 'per language' settings, like this, in settings.json:
"[go]": {
"editor.snippetSuggestions": "none",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true,
},
"vim.normalModeKeyBindings": [
{
"before": ["t"],
"commands": ["go.test.cursor"],
"when": "editorLangId == go && editorTextFocus"
},
{
"before": ["T"],
"commands": ["go.test.all"],
"when": "editorTextFocus && editorLangId == go"
}
]
},
In mocking up this scenario I noticed that VSCode hints this 'setting does not support per-language configuration.' I wonder if it's possible that VSCodeVim can somehow set these as available to be per-language configurable?
Idea 3
I have also wondered if it's possible to lean on VSCode's native keybinding system might help with things like this? Because then its context information would be available, and perhaps even used, before VSCodeVim even has to worry about the keybinding.
I'm not sure how feasible it is to get VSCode to allow non-modifier keys as keybindings though.
Also in this scenario a helper plugin like macros might be needed to get the same kind of functionality we're used to in VSCodeVim because vanilla VSCode doesn't support multiple calls.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no implementation files or tests. Start by reviewing VS Code's native keybinding and context APIs, then inspect the extension's existing keybinding handling. A complete change would define and implement one supported approach for language-aware keybindings, with tests or documented behavior covering the proposed contexts.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript, vscode
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100