编辑器和终端中 VSCode 中 R 赋值运算符 (<-) 的键盘快捷键

Rap*_*ter 5 keyboard-shortcuts r visual-studio-code

如何为在编辑器终端中都有效的基本赋值运算符( )添加键盘快捷键?<-

让它在编辑器中工作很简单(内容进入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": " <- "}
}
Run Code Online (Sandbox Code Playgroud)

但我很难理解when终端的条款需要是什么样子。

我根据有关when子句的官方文档尝试过的事情:

  • 使用terminalFocus
{
    "key": "alt+-",
    "command": "type",
    // "when": "editorLangId == r && editorTextFocus || editorLangId == rmd && editorTextFocus || terminalFocus",
    "args": {"text": " <- "}
}
Run Code Online (Sandbox Code Playgroud)
{
    "key": "alt+-",
    "command": "type",
    // "when": "editorLangId == r && editorTextFocus || editorLangId == rmd && editorTextFocus || editorLangId == shellscript && terminalFocus",
    "args": {"text": " <- "}
}
Run Code Online (Sandbox Code Playgroud)

Mar*_*ark 5

您无法使用该type命令写入终端。试试这个:

{
  "key": "alt+-",  // or whatever keybinding you want
  "command": "workbench.action.terminal.sendSequence",
  "args": {
      "text": " <- "
  },
  "when": "terminalFocus && !terminalTextSelected"
}
Run Code Online (Sandbox Code Playgroud)

请参阅将文本发送到终端文档