gpt4 book ai didi

r - 在 VS Code/R 中选择代码块或段落

转载 作者:行者123 更新时间:2023-12-05 02:36:28 26 4
gpt4 key购买 nike

我想通过快捷方式选择 R 代码块。

目前我正在使用 CTRL+L 选择当前行,并使用 CTRL+ALT+UP/DOWN 展开选择。然而,这很麻烦。

有没有办法告诉 VS Code 选择段落中的所有内容?

例子:

library(dplyr)

starwars %>%
filter(species == "Droid")

starwars %>%
|mutate(name, bmi = mass / ((height / 100) ^ 2)) %>% # <- The cursor is where "|" is for example
select(name:mass, bmi)

这是本例中应选择的内容:

starwars %>% 
mutate(name, bmi = mass / ((height / 100) ^ 2)) %>%
select(name:mass, bmi)

最佳答案

这可以借助扩展来完成。参见,例如 Select By您可以在其中指定键绑定(bind)中的开始和结束正则表达式的扩展。键绑定(bind):

{
"key": "alt+q", // whatever you want
"command": "selectby.regex",
"args": {
"flags": "m",
"backward": "^\\w", // since your block starts flush left apparently
"forward": "\n^$", // stop at first empty line
"forwardInclude": false,
"backwardInclude": true
}
}

这是我写的:Jump and Select .使用此键绑定(bind):

{
"key": "alt+q", // whatever keybinding you want
"command": "jump-and-select.jumpBackwardSelect",
"args": {
"text": "^\\w",
"putCursorBackward": "beforeCharacter",
"restrictSearch": "document"
}
}

这应该选择从光标回到第一个空白行(给定结构良好的代码示例)。

jump and select backward from cursor


要从任何地方选择 block ,您还需要一个宏扩展,如 multi-command这个键绑定(bind):

{
"key": "alt+q",
"command": "extension.multiCommand.execute",
"args": {
// "interval": 200,
"sequence": [
{
"command": "jump-and-select.jumpBackward",
"args": {
"text": "^\\w",
"putCursorBackward": "beforeCharacter",
}
},
{
"command": "jump-and-select.jumpForwardSelect",
"args": {
"text": "^[^\\w]$\n?",
"putCursorBackward": "afterCharacter",
}
}
]
},
"when": "editorFocus"
},

select entire block: r language


关于r - 在 VS Code/R 中选择代码块或段落,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70246326/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com