Appendix C — Keyboard Shortcuts
Introduction
Using keyboard shortcuts for document editing—rather than reaching for your mouse—can boost productivity. 1 ^, 2
RStudio
Below are the most useful RStudio keyboard shortcuts.
To view all of RStudio’s keyboard shortcuts, click Tools –> Keyboard Shortcuts Help or use the keyboard shortcut
To customize these shortcuts, click Tools –> Modify Keyboard Shortcuts…
Tab Completion
After typing the second letter of a function or object name (in the Editor or Console), the autocomplete menu pops up. Use the arrow keys to select from the menu then hit TabTab or EnterEnter to be typed automatically. Tab completion also works for function arguments.
Working in Source Files
Below are some useful keyboard shortcuts when working in source files, eg, Quarto files.
Action | Windows ![]() |
Mac ![]() |
---|---|---|
Insert code chunk | Ctrl Alt I |
Option Command I |
Insert pipe operator (|> ) |
Ctrl Shift M |
Command Shift M |
Insert assignment operator (<- ) |
Alt - |
Option - |
Run current code chunk | Ctrl Shift Enter |
Command Shift Return |
Run current line/currently selected lines | Ctrl Enter |
Command Return |
(Un)comment current line/currently selected lines | Ctrl Shift C |
Command Shift C |
Reformat select part of code | Ctrl Shift A |
Command Shift A |
- When running a single line of code, your cursor can be anywhere on the line–it doesn’t need to be all the way at the beginning or end.
- When running code that is selected across multiple lines, exactly what is selected is run.
- If you want to run part of a line, select just that part.
- If you want to run multiple whole lines, select all those lines in their entirety.
- When commenting/uncommenting lines, you don’t need to have the whole line fully selected. Having just part of a line selected suffices.
Working in Console
While you may be used to writing all of your code in code chunks within a document, it is often useful to run code interactively in the Console as “scratch work.” You’ll often find that when testing out code, trying it out in the Console keeps your code document clean.
Action | Windows ![]() |
Mac ![]() |
---|---|---|
Move cursor to the Console | Ctrl 2 |
Ctrl 2 |
Cycle through previous commands | Up/Down |
Up/Down |
Show pop up of command history | Ctrl Up |
Command Up |
Interrupt currently executing command | Esc |
Esc |
You can pull up the documentation (help page) for a function by entering ?function_name
in the Console.
Andrew Cohen, Founder and CEO of Brainscape, estimated that one can save 8 days per year when using keyboard shortcuts effectively (Brainscape.com).↩︎
There are many online tutorials for RStudio keyboard shortcuts with different levels of quality and details, eg, Appsilon has GIF illustrations and advanced shortcuts.↩︎