3.1 Keyboard shortcuts
| Shortcuts | Function |
|---|---|
cmd + / |
comment |
shift + cmd + M or shift + ctrl + M |
In script editor: user defined; %>% |
ctrl + P |
In Radian: user defined; %>% |
opt + - |
user defined; <- |
ctrl + ` |
toggle btw editor and terminal |
For commonly used general keyboard shortcuts (not limited to R), see HERE.
Suggested keyboard shortcuts for R in VS Code.
For user defined shortcuts, you can add them in the
keybindings.jsonfile.
Q: How to run R code interactively?
A: Create an R terminal via command R: Create R Terminal in the Command Palette. Once an R terminal is ready, you could either select the code or put the cursor at the beginning or ending of the code you want to run, press (Ctrl + Enter), and then code will be sent to the active R terminal.
If you want to run an entire R file, open the file in the editor, and press Ctrl+Shift+S and the file will be sourced in the active R terminal.
Q: Why using VS Code for R programming instead of RStudio?
A: Several reasons:
- Better integration with Copilot, making it easier to write code with AI assistance.
- More responsive and powerful engineering tools such as symbol highlight, find references, rename symbol, etc. integrated to the IDE.
- VS Code has a lot of extensions that can enhance your R programming experience, such as
Markdown Preview Enhance,Live Server, andGitLens. - Git support is better in VS Code, making it easier for version control and collaboration.