…and other keyboard shortcuts to make you a more efficient programmer
Sam Csik | Data Training Coordinator National Center for Ecological Analysis & Synthesis
Master of Environmental Data Science | Fall 2022 Bren School of Environmental Science & Management
Slides & source code available on
Keyboard shortcuts…are they really worth my time?
Because both your hands remain on the keyboard, shortcuts are often faster than a mouse
Yes, learning shortcuts does take some patience and practice, but it will save you time in the long run
Good news: lots keyboard shortcuts are universal, meaning you can use them across a variety applications
Looking for more shortcuts? Clicking on or hovering over menu items/buttons in many applications will reveal the corresponding keyboard shortcut
Make it a game
shortcutFoo was created by programmers for programmers in an attempt to make learning your editor fun, easy, and effective. Akin to the days of first learning how to type on a keyboard, shortcutFoo aims to help programmers accomplish more in less time and with fewer keystrokes.
Learn and practice shortcuts for all your favorite applications – ranging from IDEs like RStudio and VSCode to apps like Twitter, GitHub, and Slack. Start a new game here.
Mac vs. Windows
Keyboard shortcuts typically involve pressing two or more keys in a specific order. Most times, the key combos include at least one of the following: control, option, command, alt.
Macs use control, option, and command keys
Windows machines use the ctrl (Control) and alt keys
Look up function documentation for a highlighted function: Fn + F1
iframe
Look up function documentation for a highlighted function: Fn + F1
Windows users: If your Fn key is not working, look for an Fn lock button (often shared with the Esc key). Press Fn + Fn lock to unlock the F row. Then use Fn + F1 to look up function documentation.
Code snippets allow you to more quickly produce code by typing an abbreviated version of a function, which RStudio then auto-completes and/or fills in placeholders for the necessary arguments. You can check out all default code snippets by navigating to Tools > Global Options > Code > Edit Snippets…. To use a snippet, type its keyword (you see a pop up that denotes the keyword as a {snippet}), then tab to auto-complete. Use the tab key to move across and fill in any text placeholders.
Adding custom code snippets
You can create your own custom code snippets by adding them to the Edit Snippets… editor. The structure of a snippet is as follows:
Maximize source editor (script): control + shift + 1
Maximize console: control + shift + 2
Maximize plot window: control + shift + 6
Return to four pane view: control + shift + 0
iframe
Maximize source editor (script): control + shift + 1
Maximize console: control + shift + 2
Maximize plot window: control + shift + 6
Return to four pane view: control + shift + 0
Move your cursor to different panes (but not maximize that pane) by using the same key combinations as above sans shift (e.g. if my cursor is in the source editor and I would like to jump to the console, use control + 2, then control + 1 to jump back to the source editor).
Code folding
Any comment line which includes at least 4 trailing -, =, or # automatically creates a code section. You can read more about code folding here. Also check out the {ARTofR} package for creating fancier code sections!
Restart your R session: control + shift + (Fn) + F10
Jump to the top-level RProject folder
You can easily jump back to your RProject’s root directory if you have navigated away from it by clicking on the R hex icon in the top right corner of RStudio’s Files pane (thanks for the tweet tip@JennyBryan!).
The RStudio IDE makes using a whole lot easier (and more fun). We will explore some of the many ways you can customize your RStudio IDE.
RStudio Appearance
Change the appearance of RStudio by choosing Tools > Global Options > Appearance and try out different options from the Editor font, Editor font size, and Editor theme drop downs.
Rearrange Pane Layout
Change the pane layout (and add additional panes!) by choosing Tools > Global Options > Pane Layout and select what you would like in each RStudio quadrant.
Soft wrap long lines & rainbow ( )
Soft wrap long lines to make all code/text visible, even on a small window. Enable rainbow parentheses to easily identify matching opening/closing parentheses.
Without soft wrap and rainbow ()
With soft wrap and rainbow ()
Soft wrap long lines & rainbow ( )
Enable soft wrap and rainbow parentheses by choosing Code -> Soft Wrap Long Lines and Rainbow parentheses from the top menu bar.
Open multiple RStudio sessions
You may have more than one RStudio session (i.e. R project) open at a time. Click on your currently-open project at the top right corner of RStudio. Choose either Open Project in New Session… to browse all of your R projects, or click on the new window icon next to one of your more recently opened projects. Doing so will pop open an additional RStudio window with that project.
Change console output limit
Change the console output limit by choosing Tools -> Global Options -> Console -> check the box next to Limit Visible Console Output and update the value in the Limit output line length to:
Set knitr code chunks options (RMarkdown)
Easily update knitr code chunk options (e.g. code chunk name, showing warnings and errors, figure sizes, chunk output type) by clicking on the gear icon in the top right corner of a code chunk.
shortcuts & customization tips
VS Code is a versatile IDE that supports many different languages. Here are just a few helpful tips to get you going.
The Command Palette provides access lots of different commands – use this to easily connect to a server, find debugging tools, search extension-specific functionality, and more.
Arrange your tabs in different layouts – navigate to View > Editor Layout to pick the one that works best for you. Drag files tabs to arrange them across your multiple viewer panes.
shortcuts
Jupyter Notebooks are popular for teaching Python and sharing code, outputs, and prose together. Learning a few keyboard shortcuts can make writing code/markdown and executing/navigating cells much faster.
Note: Jupyter Notebooks have two modes: edit (denoted by a green border around the cell) and command (denoted by a blue border around the cell). Some shortcuts apply to just edit or just command mode (and some are the same regardless).