When coding along with others in RStudio, the inevitable “woah, how did you do that?!” occurs when commenting out multiple lines at once, copying multiple lines down at once, or moving lines around all without touching the mousepad.

Because the complete list is totally overwhelming, I’ve created this short list of shortcuts I use most often and that tend to catch people’s attention (particularly the “gems” under “editing” and “navigation”).

You can view the source code to build this document on GitHub.

A complete list of shortcuts can be accessed within RStudio using ALT + SHIFT + K, or here.

Execution

Description Keystroke Gem
Run line or selection CTRL + ENTER
Run line (without moving cursor) ALT + ENTER
Run from beginning to line CTRL + ALT + B
Run from line to end CTRL + ALT + E

Editing

Description Keystroke Gem
Copy selection CTRL + C
Cut selection CTRL + X
Paste selection CTRL + V
Undo CTRL + Z
Comment selected lines CTRL + SHIFT + C
Copy selected lines ALT + SHIFT + /
Move selected lines ALT + /
Find CTRL + F

Selection

Description Keystroke Gem
Select all code CTRL + A
Select characters SHIFT + /
Select line SHIFT + /
Select word CTRL + SHIFT + /

Files

Description Keystroke Gem
Save file CTRL + S
Open file CTRL + O
New .R script CTRL + SHIFT + N

Misc

Description Keystroke Gem
Zoom In CTRL + SHIFT + +
Zoom Out CTRL + -

‘rmarkdown’

Description Keystroke Gem
Insert an empty code chunk CTRL + ALT + I
knit a ‘rmarkdown’ document CTRL + SHIFT + K
Build a ‘bookdown’ document CTRL + SHIFT + B

‘devtools’

Description Keystroke Gem
Create package documentation CTRL + SHIFT + D
Build a package CTRL + SHIFT + B
Check a package CTRL + SHIFT + E

A complete list of shortcuts can be accessed within RStudio using OPTION + SHIFT + K, or here.

Execution

Description Keystroke Gem
Run line or selection CMD + ENTER
Run line (without moving cursor) OPTION + ENTER
Run from beginning to line CMD + OPTION + B
Run from line to end CMD + OPTION + E

Editing

Description Keystroke Gem
Copy selection CMD + C
Cut selection CMD + X
Paste selection CMD + V
Undo CMD + Z
Comment selected lines CMD + SHIFT + C
Copy selected lines CMD + OPTION + /
Move selected lines OPTION + /
Find CMD + F

Selection

Description Keystroke Gem
Select all code CMD + A
Select characters SHIFT + /
Select line SHIFT + /
Select word OPTION + SHIFT + /

Files

Description Keystroke Gem
Save file CMD + S
Open file CMD + O
New .R script CMD + SHIFT + N

Misc

Description Keystroke Gem
Zoom In CMD + =
Zoom Out CMD + -

‘rmarkdown’

Description Keystroke Gem
Insert an empty code chunk CMD + SHIFT + I
knit a ‘rmarkdown’ document CMD + SHIFT + K
Build a ‘bookdown’ document CMD + SHIFT + B

‘devtools’

Description Keystroke Gem
Create package documentation CMD + SHIFT + D
Build a package CMD + SHIFT + B
Check a package CMD + SHIFT + E


NOTES