在VSCode的编辑器和终端中,R赋值运算符(<-)的键盘快捷键是什么?

5
如何为基本的赋值运算符<-)添加一个键盘快捷方式,使其在编辑器终端中都可以使用?
使其在编辑器中工作是直接的(将内容放入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": " <- "}
}

但我还不太明白终端需要怎样的when子句。
根据官方文档上的when子句,我尝试了以下方法:
  • 使用terminalFocus
{
    "key": "alt+-",
    "command": "type",
    // "when": "editorLangId == r && editorTextFocus || editorLangId == rmd && editorTextFocus || terminalFocus",
    "args": {"text": " <- "}
}

基于官方文档的额外明确语言ID。
{
    "key": "alt+-",
    "command": "type",
    // "when": "editorLangId == r && editorTextFocus || editorLangId == rmd && editorTextFocus || editorLangId == shellscript && terminalFocus",
    "args": {"text": " <- "}
}

我如何访问 keybindings.json 文件? - jglad
@Rappster 你好。有没有办法让“<-”在Emacs中的行为一样?也就是说,按下“ctrl+_”一次,你就得到“<-”;按两次,你得到下划线“_”本身。感谢。 - undefined
1个回答

5
你不能使用 type 命令来向终端写入内容。请尝试使用以下方法:
{
  "key": "alt+-",  // or whatever keybinding you want
  "command": "workbench.action.terminal.sendSequence",
  "args": {
      "text": " <- "
  },
  "when": "terminalFocus && !terminalTextSelected"
}

查看 将文本发送到终端文档


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接