I've succesfully added keybindings for %>%
and <-
when working with R scripts or Rmarkdown in Visual Studio Code by adding the following to my keybindings.json
file:
{
"key": "Ctrl+Shift+m",
"command": "type",
"args": { "text": " %>% " },
"when": "editorTextFocus && editorLangId == r"
},
{
"key": "Alt+-",
"command": "type",
"args": { "text": " <- " },
"when": "editorTextFocus && editorLangId == r"
},
{
"key": "Ctrl+Shift+m",
"command": "type",
"args": { "text": " %>% " },
"when": "editorTextFocus && editorLangId == rmd"
},
{
"key": "Alt+-",
"command": "type",
"args": { "text": " <- " },
"when": "editorTextFocus && editorLangId == rmd"
},
But I can't figure how to do that for my R terminal inside Visual Studio Code. Any ideas?
@AdroMine found the way to do it. I'll just post the updated keybindings.json so that others can use it:
[
// OTHER KEYBINDINGS,
// keybindings for R scripts.
{
"key": "Ctrl+Shift+m",
"command": "type",
"args": { "text": " %>% " },
"when": "editorTextFocus && editorLangId == r"
},
{
"key": "Alt+-",
"command": "type",
"args": { "text": " <- " },
"when": "editorTextFocus && editorLangId == r"
},
// keybindings for Rmarkdown
{
"key": "Ctrl+Shift+m",
"command": "type",
"args": { "text": " %>% " },
"when": "editorTextFocus && editorLangId == rmd"
},
{
"key": "Alt+-",
"command": "type",
"args": { "text": " <- " },
"when": "editorTextFocus && editorLangId == rmd"
},
// keybindings for R terminal (radian included)
{
"key": "Ctrl+Shift+m",
"command": "workbench.action.terminal.sendSequence",
"args": { "text": " %>% " },
"when": "terminalFocus"
},
{
"key": "Alt+-",
"command": "workbench.action.terminal.sendSequence",
"args": { "text": " <- " },
"when": "terminalFocus"
},
// OTHER KEYBINDINGS
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With