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 + ⇨ / ⇦
|
|
Navigation
Description
|
Keystroke
|
Gem
|
Move cursor between words
|
CTRL + ⇨ / ⇦
|
|
Move cursor to end or start of line
|
ALT + ⇨ / ⇦
|
|
Move cursor to script editor pane
|
CTRL + 1
|
★
|
Move cursor to console pane
|
CTRL + 2
|
★
|
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
|
|
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 + ⇨ / ⇦
|
|
Navigation
Description
|
Keystroke
|
Gem
|
Move cursor between words
|
OPTION + ⇨ / ⇦
|
|
Move cursor to end or start of line
|
CMD + ⇨ / ⇦
|
|
Move cursor to script editor pane
|
CTRL + 1
|
★
|
Move cursor to console pane
|
CTRL + 2
|
★
|
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
|
|
NOTES
- This list is by no means comprehensive.
- Shortcuts labeled as ★ under the Gem column are those that I personally find especially useful and are specific to my work in RStudio, beyond the basics. For example, the shortcut for “Undo” is among my most frequently used keystrokes, but it is basic in that many other programs use this same one.
- If there is a highly useful shortcut you believe is missing from this list, please submit an issue, and I will consider adding it.
- If you find an error here, please do the same.