Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add keybindings in Visual Studio Code for the R terminal

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?

like image 339
arnle Avatar asked Oct 17 '25 13:10

arnle


1 Answers

@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

]



like image 50
arnle Avatar answered Oct 20 '25 02:10

arnle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!