Skip to content

Keyboard Shortcuts

Julia Silge edited this page Jul 18, 2024 · 3 revisions

Positron's keyboard shortcuts, with a few exceptions, are a superset of the keyboard shortcuts used by Visual Studio Code. This table lists the shortcuts specifically added for Positron.

Global Shortcuts

Shortcut Description
Cmd/Ctrl+Enter Run the selected code in the editor. If no code is selected, run the current statement.
Cmd/Ctrl+Shift+0 Restart the interpreter currently open in the Console
Cmd/Ctrl+Shift+Enter Run the file open in the editor (using e.g. source() or %run)
F1 Show contextual help for the topic under the cursor
Cmd/Ctrl+K, Cmd/Ctrl+R Show contextual help for the topic under the cursor (alternate binding)
Cmd/Ctrl+K, F Focus the Console
Ctrl+L Clear the Console

R Shortcuts

Shortcut Description
Cmd/Ctrl+Shift+M Insert the pipe operator (|> or %>%)
Alt+- Insert the assignment operator (<-)
Cmd/Ctrl+Shift+L Load the current R package, if any
Cmd/Ctrl+Shift+B Build and install the current R package, if any
Cmd/Ctrl+Shift+T Test the current R package, if any
Cmd/Ctrl+Shift+E Check the current R package, if any
Cmd/Ctrl+Shift+D Document the current R package, if any

RStudio Keymap

If you'd prefer to use RStudio keybindings, do the following:

  • Open Positron's settings (Cmd+, or Ctrl+,)
  • Search for "keymap", or navigate to Extensions > RStudio Keymap
  • Check the "Enable RStudio key mappings for Positron" checkbox

The following RStudio keymappings will be enabled:

Shortcut Description
Ctrl+1 Focus Source
Ctrl+2 Focus Console
Cmd/Ctrl+. Go to Symbol
Cmd/Ctrl+Shift+C Comment/Uncomment a line
Cmd/Ctrl+Shift+N Create a new R file
F2 Go to definition
Cmd/Ctrl+I Reindent selection
Cmd/Ctrl+Shift+A Reformat selection
Cmd/Ctrl+Shift+S Source the current R script
Cmd/Ctrl+Alt+Shift+M Rename
Cmd/Ctrl+Alt+I Insert a new Quarto/R Markdown cell
Cmd/Ctrl+Alt+M Open version control pane
Cmd/Ctrl+Alt+Left Go to previous tab
Cmd/Ctrl+Alt+Right Go to next tab
Cmd/Ctrl+D Delete the current line
Cmd/Ctrl+Shift+M Insert pipe operator
Cmd/Ctrl+Shift+R Insert section
Alt+Shift+K Open global keybindings list
Alt+- Insert left assignment operator <-

Custom Shortcuts

Because Positron is built on top of VS Code, you can use its infrastructure for defining custom keybindings. You can use this infrastructure with any Positron-specific commands, such as workbench.action.executeCode.console or workbench.action.executeCode.silently. As a specific example, you could add this to your user keybindings.json (access this file from the command palette with "Open Keyboard Shortcuts (JSON)") to make a keyboard shortcut to create a reprex from your current selection:

{
    "key": "Cmd+Shift+R",
    "command": "workbench.action.executeCode.console",
    "when": "editorTextFocus",
    "args": {
        "langId": "r",
        "code": "reprex::reprex_selection()",
        "focus": true
    }
}
Clone this wiki locally