7 Keyboard Shortcuts

Keyboard shortcuts tend to make our lives easier. Some that you might already be familiar with in day to day life are: quickly saving (Cmd + S or Ctrl + S), or Undo (Cmd + Z or Ctrl + Z).
There are many keyboard shortcuts you can access in R, this section provides a brief tour of them, and why you might want to use them.
7.1 Overview
- Teaching 5 minutes
- Exercises 5 minutes
7.2 Questions
- What sort of keyboard shortcuts should I care about?
7.3 Objectives
7.4 Table of Common Shortcuts
Below is a small table of tasks you can perform with keyboard shortcuts
| Action | Windows/Linux | Mac |
|---|---|---|
| Command Palette | Ctrl + Shift + P | Cmd + Shift + P |
| Render document | Ctrl + Shift + K | Cmd + Shift + K |
| Insert Chunk | Ctrl + Alt + I | Cmd + Option + I |
| Run current line or selection | Ctrl + Enter | Cmd + Return |
| Run Current Chunk | Ctrl + Alt + C | Cmd + Option + C |
| Show Keyboard Shortcut Reference | Alt+Shift+K | Option+Shift+K |
| Create multiple cursors | Ctrl + Alt + Up/Down | option + control + Up/Down |
| Delete the current line | Ctrl + D | Cmd + D |
| Un/Comment out a line | Ctrl + Shift + C | Cmd + Shift + C |
| Reformat Section | Ctrl + Shift + A | Cmd + Shift + A |
| Move lines up/down | Alt + Up/Down | Option + Up/Down |
| Copy lines up/down | Shift + Alt + Up/Down | Cmd + Option + Up/Down |
| Jump to Word | Ctrl + Left/Right | Option + Left or Right |
| Select to Word | Ctrl + Shift + Left/Right | Option + Shift + Left or Right |
| Jump to Line Start/End | Alt + Left/Right | Cmd + Left or Right |
| Select to Line Start/End | Shift + Alt + Left/Right | Shift + Cmd + Left or Right |
7.5 Further Reading
- The Rstudio Cheat Sheet has an index of shortcuts.
- This help file has a guide to customising keyboard shortcuts.
- The shrtcts R package for creating new shortcuts.
- My course R Best Practices goes further into this, covering typing speed, working closer to the speed of thought, and a longer list of shortcuts worth learning.
NoteYour Turn
- In your awesome quarto document
- Practice using the Keyboard Shortcut Reference and find the keyboard shortcut for inserting a pipe character (
%>%or|>) - Find the keyboard shortcut for inserting assignment (
<-) - Read the “Editing (console and source)” shortcuts
- Spend 5 minutes practicing these commands. Really!
- Practice using the Keyboard Shortcut Reference and find the keyboard shortcut for inserting a pipe character (
- Ask Nick to demonstrate some of his favourite shortcut combos
- e.g., multiline cursor, yank lines, copy lines, go to file/function