Keyboard shortcuts

I think the only shortcut that came premapped that I use is for commenting out chunks of code: Ctrl+Shift+C

I then have three custom mappings which I use all the time:

F3 - Run highlighted code
F4 - Run entire code script
F5 - Knit .Rmd Files

Edit: I came up with these as I was used to SAS Programming before switching most of my efforts to R & RStudio. In SAS, F3 also runs the highlighted code chunk and so it expanded from there based on habit.

  • Alt + Shift + / to duplicate lines (code duplication is to be avoided, but...)
    (just discovered Ctrl + Shift + D that does almost the same)

  • Alt + / to move line(s): very often one I've just duplicated, or can be a code chunk, or a single line in a %>%-line, or reorder my library() statements, that kind of things

  • Ctrl + Shift + F to "grep" code in my project (especially in the context of Discerning intra-code dependencies)

  • F1 for help

  • F2 for definition

1 Like

It is more a keyboard shortcut that goes with using RStudio, than a RStudio shortcut, but yesterday I spent a bunch of time mourning that I had not know the keyboard shortcut on a Macintosh for copy the POSIX path of the select file in Finder is Command + Option + c

That is one that would have saved many many hours when writing scripts.

1 Like

Thanks a bunch. This is super useful!

Besides the shortcuts for running code and building packages, definately f2 (go to function source)

cmd + shift + M
alt + shift + T
ctl + 2

Cmd + shift + K for markdowns all day

1 Like

I mapped alt + - to the assignment operator “<-“ and it has made life soooo much easier

1 Like

I use this one a lot. Except I use the default hotkey option + - . I think I use the pipe hotkey the most though, command + shift + m


Ah you know what, I use the default for assignment also :slight_smile: I actually meant to say I re-mapped the pipe to command + .

Makes it just that bit faster instead of having to hold down three keys

1 Like

I see the assigned keyboard shortcuts, but is there a URL for shortcuts that haven't been assigned yet?

I see the list in the IDE itself, but it would be handy to have it on a web page that I can refer to.

standard used in quite every anythings

  • ctrl + c: copy
  • ctr + v: paste
  • ctr + x: cut
  • ctrl + z: undo
  • ctrl + shift + z: restore undo
  • ctrl + a: select all
  • ctrl + f: find/replace
  • ctrl + w: close active tab

Rstudio specific

  • ctrl + shift + n: new script
  • alt + -: insert assignment operator correctly spaced
  • ctrl + Enter: run block of code
  • ctrl + shift + F10: restart R
  • ctrl + shift + s: source the active file
  • ctrl + shift + i: insert chunk
  • ctrl + shift + m: insert pipe
  • ctrl + l: clean the console
  • ctrl + shift + c: comment selected lines (or active line)
  • F1: help
  • F2: source code of function
  • ctrl + alt + double left click: multiple word selection
  • alt + hold left click: free cursor positioning or rectangular selection
  • alt + ctrl + (multi) single left click: free (multi) positioning cursor
  • [on the console] (some typing +) ctrl + up-arrow: inspect the history (filtered according to start with "some typing")

Last night I remapped the Shift + space to add tabs (or 2 spaces) in editor.

I will be using this a lot.

The tab activates code completion, and from what I've read there's no way to turn that off outside of a custom build of R studio.

The shortcut Ctrl + Alt + E (Run From Line to End) is not working for me. Does anyone have the same problem?

What annoyed me most is that "ctrl + shift + R" on Rstudio server reloads browser page instead of inserting section as in Rstudio desktop.
does anyone know how to make all shortcuts the same for browser Rstudio and Desktop Rstudio?

My favourite, by the way is "ctrl + shift + A" for reformatting code

Any idea why ctrl + alt + I doesn't insert a code chunk in windows. It just created a weird symbol "í" in my computer.

A post was split to a new topic: Create a shortcut to jump to History based on selection

I had the same issue. I decided it was good to be able to keep the shortcuts CtrlAlt$vowel for accented characters, and I just remapped the shortcut for insert chunk to a different combination (I used CtrlAlt' but you could use anything else suitable).

I use CtrlAlt. to insert a %>% pipe... Basically I kept hitting that combination instead of Ctrl-Alt-M (my mind associates the > on the . key with the pipe) so I thought I might as well just go with it :smile: