Skip to content

feat: opt-in RStudio keyboard shortcuts (r.keybindings.rstudio) - #1885

Open
roaldarbol wants to merge 1 commit into
REditorSupport:mainfrom
roaldarbol:feat/rstudio-keymap
Open

roaldarbol wants to merge 1 commit into
REditorSupport:mainfrom
roaldarbol:feat/rstudio-keymap

Conversation

@roaldarbol

Copy link
Copy Markdown

Follows up on #1787 (formerly #551), where an opt-in setting for RStudio-like keymaps was suggested and marked as help wanted.

What

A setting, r.keybindings.rstudio (off by default), that turns on RStudio's R-specific shortcuts:

Shortcut (macOS: Cmd for Ctrl) Does Where Replaces there
Alt+- inserts <- R, R Markdown, Quarto files –
Ctrl+Shift+M inserts the pipe from r.keybindings.pipe: |> (native, default) or %>% (magrittr) R, R Markdown, Quarto files Problems
Ctrl+Shift+L r.loadAll R, R Markdown files Select All Occurrences
Ctrl+Shift+T r.test R, R Markdown files Reopen Closed Editor
Ctrl+Shift+D r.document R, R Markdown files Run and Debug view
Ctrl+Shift+E r.check R, R Markdown files Explorer view
Ctrl+Shift+B r.install R, R Markdown files Run Build Task

Following the discussion's caveats, it covers R-specific shortcuts only, not RStudio's general editor ones, and they apply only in R files.

How

Only package.json: the keybindings are contributed with config.r.keybindings.rstudio (and config.r.keybindings.pipe) in their when clauses, as LaTeX Workshop does for its alternative keymap. So there's one set of default keybindings, and the RStudio one is a setting away. Because it's a setting, it can also be turned on for a team, e.g. in a dev container's customizations.vscode.settings, which is how I came to this: our R developers shouldn't each have to copy keybindings into their own keybindings.json for every project.

Open questions

  • The R console. RStudio's Alt+- and Ctrl+Shift+M also work in the console. A terminal binding (workbench.action.terminal.sendSequence) needs to know the focused terminal is an R one, or it would also fire in e.g. bash. There's no context key for that yet; TerminalSessionRegistry / switchSessionByTerminal could set one (say r.terminalFocus). Would you want that here, or separately?
  • Names and scope: r.keybindings.rstudio / r.keybindings.pipe, and whether the devtools shortcuts belong in (they override more VS Code defaults than the two inserts).
  • Docs: the Keyboard shortcuts wiki page would mention the setting.

Testing

Draft: checked that package.json is valid, that every keybinding's command exists, and that both settings are declared. Not yet tried in the Extension Development Host.

🤖 Generated with Claude Code

With r.keybindings.rstudio on (off by default): Alt+- inserts <- and Ctrl/Cmd+Shift+M the pipe chosen in
r.keybindings.pipe (native |> or magrittr %>%) in R, R Markdown and Quarto files; Ctrl/Cmd+Shift+L/T/D/E/B load
all, test, document, check and install the package in R and R Markdown files. Keybindings with config.* when
clauses, as in LaTeX Workshop, so a setting (e.g. in a dev container) turns them on for everyone.

Discussed in REditorSupport#1787 (formerly REditorSupport#551).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@roaldarbol
roaldarbol marked this pull request as ready for review October 20, 2026 09:40

@eitsupi eitsupi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is based on an analysis by ChatGPT.

I have several concerns about adding RStudio-specific keybindings to vscode-R itself.

  • VS Code already provides a flexible mechanism for users to configure individual keybindings. I'm not convinced we need an additional setting to manage them.
  • Enabling r.keybindings.rstudio overrides several standard VS Code shortcuts at once. The effects are not immediately obvious from the setting name, and users may want to enable some shortcuts without replacing others.
  • The bindings also apply to R Markdown and Quarto files without checking whether the cursor is inside an R code chunk. This means R-specific shortcuts can be triggered while editing Markdown, YAML, or even non-R code chunks.
  • I think vscode-R should focus on providing R-specific commands, while leaving key assignments to VS Code's existing keybinding mechanism.
  • If distributing a predefined keymap is important, a separate keymap extension would provide a clearer separation of responsibilities.

While sharing keybindings across a team is a valid use case, I would prefer documenting the suggested mappings in the Wiki so users can copy and customize them in keybindings.json, rather than introducing additional settings and maintaining an RStudio-specific keymap in vscode-R.

@ThomasSoeiro

Copy link
Copy Markdown
Collaborator

I agree with @eitsupi that we should avoid adding keybindings that conflict with VSCode's default keybindings. I'd even suggest removing keybindings defined by the extension, at least those that conflict with VS Code defaults (notably Ctrl+Shift+S).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants