I would like to select an R code block via a shortcut.
At the moment I am using CTRL+L
to select the current line and CTRL+ALT+UP/DOWN
to expand the selection. This, however, is cumbersome.
Is there any way to tell VS Code to select everything in a paragraph?
Example:
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)
This is what should be selected in this example:
starwars %>%
mutate(name, bmi = mass / ((height / 100) ^ 2)) %>%
select(name:mass, bmi)
This could be done with the aid of an extension. See, e.g., the Select By extension in which you can specify the starting and ending regex within the keybinding. Keybinding:
{
"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
}
}
Here is one that I wrote: Jump and Select. Use this keybinding:
{
"key": "alt+q", // whatever keybinding you want
"command": "jump-and-select.jumpBackwardSelect",
"args": {
"text": "^\\w",
"putCursorBackward": "beforeCharacter",
"restrictSearch": "document"
}
}
This should select from the cursor back to the first blank line (given your well-structured code examples).
To select the block from anywhere, you also need a macro extension like multi-command and this keybinding:
{
"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"
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With