我如何在vscode中为R中的magrittr管道设置别名

我想要在vscode中键入self.navigationBar.setTitleVerticalPositionAdjustment(ajustment,for:.default) 的别名(R中的pipe命令)。在Rstudio中,它映射为ctrl + shift + M,但是如果出于某种原因我无法映射到其他代码,则在vscode中不可用,那么我不确定如何添加新别名。

songlianghao 回答:我如何在vscode中为R中的magrittr管道设置别名

您只需要将其添加到您的keybindings.json文件中(请参阅here以了解如何打开它):

{
  "key": "Ctrl+Shift+m","command": "type","args": { "text": " %>% " },"when": "editorTextFocus"
}

这样,您就不需要宏


修改后的

keybindings.json文件:

// Place your key bindings in this file to override the defaults
[
    {
        "key": "Ctrl+Shift+m","when": "editorTextFocus"
    }
]
,

我不使用vscode,但是也许可以使用https://marketplace.visualstudio.com/items?itemName=geddski.macros使用宏。它在将参数传递给命令部分中说:

  

许多命令都接受参数,例如“ type”命令,该命令可让您将文本插入编辑器。

也许这会起作用(未经测试)。将此添加到您的settings.json

"macros": {
  "addPipe": [
    "cursorEnd",{"command": "type","args": {"text": "%>%"}}
  ]
}

并将其发送到您的keybindings.json

{
  "key": "ctrl+shift+M","command": "macros.addPipe"
}
本文链接:https://www.f2er.com/3151782.html

大家都在问