IDE Tips & Tricks

…and other keyboard shortcuts to make you a more efficient programmer Keyboard


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 GitHub

Keyboard shortcuts…are they really worth my time?

Keyboard Because both your hands remain on the keyboard, shortcuts are often faster than a mouse
Clock Yes, learning shortcuts does take some patience and practice, but it will save you time in the long run
Globe Good news: lots keyboard shortcuts are universal, meaning you can use them across a variety applications
Mouse Pointer Looking for more shortcuts? Clicking on or hovering over menu items/buttons in many applications will reveal the corresponding keyboard shortcut

Gamepad 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.
The shortcut foo landing page.

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.

Apple Mac vs. Windows 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.
Apple Macs use control, option, and command keys
Windows Windows machines use the ctrl (Control) and alt keys


General keyboard shortcuts


Become a keyboard ninja User Ninja across lots of your favorite applications with the stroke of a few keys

Copy Copy/Cut, Paste, Undo/Redo




angle-right copy: command + C
angle-right cut: command + X
angle-right paste: command + V
angle-right undo: command + Z

iframe here



angle-right copy: control + C
angle-right cut: control + X
angle-right paste: control + V
angle-right undo: control + Z

Search Find & Save Save





angle-right find: command + F
angle-right save: command + S

iframe




angle-right find: control + F
angle-right save: control + S

Highlighter Select Text



angle-right select all: command + A
angle-right select everything in a particular direction: command + shift + arrow key
angle-right select everything within a set of closed ( ): control + shift + E
angle-right select character-by-character: shift + arrow key

iframe here




angle-right select all: command + A
angle-right select character-by-character: shift + arrow key

step-forward Jump to the beginning/end of lines



angle-right Jump to beginning: command+ right arrow
angle-right Jump to end: command + left arrow
angle-right Jump one word at a time option + left/right arrow
angle-right Bonus: begin typing a function name and RStudio will suggest functions for auto-complete

iframe


angle-right Jump to beginning: Alt+ right arrow
angle-right Jump to end: Alt + left arrow
angle-right Jump one word at a time control + left/right arrow
angle-right Bonus: begin typing a function name and RStudio will suggest functions for auto-complete

arrow-left arrow-right Changing tabs



angle-right Move tabs (to the right): control + tab
angle-right Move tabs (to the left): control + shift + tab
angle-right Close tab: command + W
angle-right Open a new tab (browser): command + T

iframe


angle-right Move tabs (to the right): control + tab
angle-right Move tabs (to the left): control + shift + tab
angle-right Close tab: control + W
angle-right Open a new tab (browser): control + T

shortcuts


Quickly write/edit code and navigate the RStudio IDE using these shortcuts

Access the RStudio Keyboard Shortcut Quick Reference Guide
(Apple ) option + shift + K / (Windows ) Alt + shift + K

Code Run lines of code




angle-right Run selected line(s): command + return
angle-right Run line(s) without moving cursor: option + return

iframe



angle-right Run selected line(s): control + enter
angle-right Run line(s) without moving cursor: alt + enter

Redo Access previously executed lines of code
angle-right Move cursor into the console and use the up and down arrow keys to cycle between previously executed code in chronological order
angle-right Pull up list a of previously executed commands: First move cursor to console, then command + up arrow

iframe

angle-right Move cursor into the console and use the up and down arrow keys to cycle between previously executed code in chronological order
angle-right Pull up list a of previously executed commands: First move cursor to console, then control + up arrow

Redo Insert code chunk





angle-right Insert code chunk (into an RMarkdown file): command + option + I

iframe




angle-right Insert code chunk (into an RMarkdown file): control + Alt + I

arrow-left Operators & Hashtag Commenting Out Code




angle-right insert {magrittr} pipe operator (%>%) or native pipe (|>): control + shift + M
angle-right comment/uncomment code: command + shift + C

iframe



angle-right insert {magrittr} pipe (%>%) or native pipe (|>): control + shift + M
angle-right comment/uncomment code: control + shift + C

Alternate File Look up function documentation





angle-right Look up function documentation for a highlighted function: Fn + F1

iframe




angle-right 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.

Function creation shortcut (extract function)





angle-right Quickly create a function from existing arguments: control + option + X

iframe




angle-right Quickly create a function from existing arguments: control + Alt + X

Variable creation shortcut (extract variable)





angle-right Quickly assign an object to a variable name: control + option + V

iframe




angle-right Quickly assign an object to a variable name: control + Alt + V

I Beam Cursor Multi-line cursor





angle-right Hold option + drag in the direction you want to stretch your cursor

iframe




angle-right Hold Alt + drag in the direction you want to stretch your cursor

align-left Align messy code




angle-right Fix indentation of selected code: command + I
angle-right Reformat selected code: command + shift + A

iframe



angle-right Fix indentation of selected code: control + I
angle-right Reformat selected code: control + shift + A

Cut Code snippets
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.

Cut 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:
snippet keyword
  function(${1:input1}, ${2:input2}, ${N:inputN})

$ denotes where the cursor should jump after completing each section of a snippet. Read more about how to customize code snippets here.

Window Minimize Window Maximize Maximize panes
angle-right Maximize source editor (script): control + shift + 1
angle-right Maximize console: control + shift + 2
angle-right Maximize plot window: control + shift + 6
angle-right Return to four pane view: control + shift + 0

iframe

angle-right Maximize source editor (script): control + shift + 1
angle-right Maximize console: control + shift + 2
angle-right Maximize plot window: control + shift + 6
angle-right 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).

Eye Slash 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!


angle-right Collapse single section: option + command + L
angle-right Expand single section: option + command + shift + L
angle-right Collapse all sections: option + command + O
angle-right Expand all sections: option + command + shift + O

iframe

angle-right Collapse single section: alt + L
angle-right Expand single section: alt + shift + L
angle-right Collapse all sections: alt + O
angle-right Expand all sections: alt + shift + O

Power Off Restart R





angle-right Restart your R session: command + shift + 0

iframe




angle-right Restart your R session: control + shift + (Fn) + F10

arrow-up 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!).

RStudio IDE Cheat Sheet (1/2)
Download here!

RStudio IDE Cheat Sheet (2/2)
Download here!

Customize your RStudio IDE experience


The RStudio IDE makes using R Project a whole lot easier (and more fun). We will explore some of the many ways you can customize your RStudio IDE.

Palette 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.

th-large 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 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 rainbow ( )
Enable soft wrap and rainbow parentheses by choosing Code -> Soft Wrap Long Lines and Rainbow parentheses from the top menu bar.

plus 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.

Stop Circle 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.

Search Plus Open the Command Palette
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.




angle-right Open Command Palette: command + shift + P

iframe




angle-right Open Command Palette: control + shift + P

th-large Change the Editor Layout
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).

play Run cells



angle-right Run selected cell (either mode): control (or command) + return
angle-right Run selected cell & move to next cell (either mode): shift + return

iframe



angle-right Run selected cell (either mode): control + enter
angle-right Run selected cell & move to next cell (either mode): shift + enter

Alternate Exchange Change modes, cell types, delete cells

angle-right Change cell type to Markdown (command mode): M
angle-right Change cell type to Code: Y (command mode)
angle-right Activate command mode: esc
angle-right Activate edit mode: esc
angle-right Delete cell (command mode): DD
angle-right Undo delete cell (command mode): Z

iframe

angle-right Change cell type to Markdown (command mode): M
angle-right Change cell type to Code: Y (command mode)
angle-right Activate command mode: esc
angle-right Activate edit mode: esc
angle-right Delete cell (command mode): DD
angle-right Undo delete cell (command mode): Z

plus Insert cells & select multiple cells



angle-right Insert cell above (command mode): A
angle-right Insert cell below (command mode): B
angle-right Select multiple cells (command mode): shift + up/down arrow

iframe



angle-right Insert cell above (command mode): A
angle-right Insert cell below (command mode): B
angle-right Select multiple cells (command mode): shift + up/down arrow

Open Command Palette




angle-right Open command palette: command + shift + P

iframe




angle-right Open command palette: control + shift + P

Info Circle More help
angle-right RStudio Shortcuts and Tips (Part I), by Appsilon
angle-right RStudio Shortcuts and Tips (Part II), by Appsilon
angle-right Jupyter Notebooks Shortcuts, by Ventsislav Yordanov in Towards Data Science

Happy typing!