Reputation: 13090
How would I add a keyboard shortcut for the basic assignment operator (<-
) that works both in the editor AND the terminal?
Getting it to work in the editor is straightforward (content goes into keybindings.json
):
{
"key": "alt+-",
"command": "type",
"when": "editorLangId == r && editorTextFocus || editorLangId == rmd && editorTextFocus",
// if you want using quarto, try this
// "when": "editorLangId =~ /r|rmd|qmd/ && editorTextFocus",
"args": {"text": " <- "}
}
But I'm struggling with understanding what the when
clause would need to look like for the terminal.
Things I tried based on the official doc on when clauses:
terminalFocus
{
"key": "alt+-",
"command": "type",
// "when": "editorLangId == r && editorTextFocus || editorLangId == rmd && editorTextFocus || terminalFocus",
"args": {"text": " <- "}
}
{
"key": "alt+-",
"command": "type",
// "when": "editorLangId == r && editorTextFocus || editorLangId == rmd && editorTextFocus || editorLangId == shellscript && terminalFocus",
"args": {"text": " <- "}
}
Upvotes: 7
Views: 3294
Reputation: 182311
You can't use the type
command to write to the terminal. Try this instead:
{
"key": "alt+-", // or whatever keybinding you want
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": " <- "
},
"when": "terminalFocus && !terminalTextSelected"
}
See send text to terminal docs
Upvotes: 6