VScode中使用R语言:快捷键设置

前言

之前提到,我从使用RStudio编辑器迁移到了使用VScode编辑器,也是最近几年,VScode才有了相对成熟的R语言支持,但是,有一些方便的快捷键(或者说我用习惯了)没有被初始化设置,所以,需要我手动添加😑

RStudio 常用的快捷键

PS:当然,这里说的常用是我常用的(服务器 Rstudio server),并不涵盖所有

  1. Alt + - ,<- 赋值
  2. Ctrl + Shift + m,%>%管道符
  3. Ctrl + Shift + c,注释选中行
  4. Ctrl + Shift + F10,重新启动 R session
  5. Ctrl + 1 和 Ctrl + 2,在 R ScriptR Console之间转换
  6. Ctrl + s,保存当前 R Script
  7. Ctrl + Alt + Shift + N,新建空白 R Script
    ……

VScode 中设置 R 语言快捷键

像什么切换啊,新建啊都内置好了(比如:Ctrl + `,Ctrl + n),但是赋值啊、管道符啊、等等都没有,所以添加一下。

  1. 点击设置,然后选择键盘快捷方式, 在新出现的界面右上角,点击图标:打开键盘快捷方式(JSON)
  2. 或者 Ctrl + Shift + p 输入 keyboard,就会看见打开键盘快捷方式(Open Keyboard Shortcuts(JSON)),点击就可以打开
  3. 将设置写入JSON文件:
[
	//赋值
    {
        "key": "alt+-",
        "command": "type",
        "args": {
            "text": " <- "
        },
        "when": "editorTextFocus && editorLangId == 'r'"
    },
    {
        "key": "alt+=",
        "command": "type",
        "args": {
            "text": " -> "
        }
    },
    //特殊作用的
    {
        "key": "alt+5",
        "command": "type",
        "args": {
            "text": " %in% "
        },
        "when": "editorTextFocus && editorLangId == 'r'"
    },
    //管道符
    {
        "key": "ctrl+shift+m",
        "command": "editor.action.insertSnippet",
        "when": "editorTextFocus && editorLangId == 'r'",
        "args": {
            "snippet": " %>% "
        }
    },
    {
        "key": "ctrl+shift+,",
        "command": "editor.action.insertSnippet",
        "when": "editorTextFocus && editorLangId == 'r'",
        "args": {
            "snippet": " %<>% "
        }
    }
]

后记

因为在VScode中使用R语言,有个好用的,类似于Ipython的工具,叫radian,所以,也贴上一些radian的设置,直接放在家目录的.radian_profile配置文件中就OK:

# allows user defined shortcuts, these keys should be escaped when send through the terminal.
# In the following example, `esc` + `-` sends `<-` and `esc` + `m` sends `%>%`.
# Note that in some terminals, you could mark `alt` as `escape` so you could use `alt` + `-` instead.
options(radian.escape_key_map = list(
    list(key = "-", value = " <- "),
    list(key = "m", value = " %>% ")
))
  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值