Home > Mobile >  Add custom keyboard shortcuts based on terminal language
Add custom keyboard shortcuts based on terminal language

Time:11-15

I am trying to add custom shortcuts for R to my VS code settings. I have set a shortcut for the pipe |> operator for editor widows by adding the following to my keyboard shortcut json file.

    {
      "key": "ctrl shift m",
      "command": "type",
      "when": "editorLangId == r && editorTextFocus",
      "args": {"text": " |> "}
    }

However, this shortcut doesn't apply to the terminal. I think the when argument in the above chunk would look something like terminalLangId == r && terminalTextFocus. However, those arguments (e.g., terminalLangId) don't appear to be actual arguments used by VS code.

Can anyone provide advice on how to set language specific keyboard shortcuts for the terminal in VS code?

CodePudding user response:

To send text to the terminal you use a different command, workbench.action.terminal.sendSequence.

{
  "key": "ctrl shift m",
  "command": "type",
  "when": "editorLangId == r && editorTextFocus",
  "args": {"text": " |> "}
},
{
  "key": "ctrl shift m",
  "command": "workbench.action.terminal.sendSequence",
  "when": "terminalFocus",
  // "when": "editorLangId == r && terminalFocus",  // maybe you want this?
  "args": {"text": " |> "}
}

This will type |> in the current editor when it has focus, and if it is an r file. Or, if the terminal has focus, |> will be printed there.

  • Related