Customizing Keyboard Shortcuts in the RStudio IDE

Follow

Customizing Keyboard Shortcuts

You can now customize keyboard shortcuts in the RStudio IDE -- you can bind keys to execute RStudio application commands, editor commands, or (using RStudio Addins) even user-defined R functions.

Access the keyboard shortcuts by clicking Tools -> Modify Keyboard Shortcuts...:

You will then see the set of available editor commands (commands that affect the current document's contents, or the current selection), alongside RStudio commands (commands whose actions are scoped beyond just the current editor).

Each row represents a particular command binding -- the command's Name, the keyboard Shortcut it is bound to, and the Scope where that binding is active.

You can modify a command's shortcut by clicking on the cell containing the current shortcut key sequence, and typing the new sequence you'd like to bind the command to. As you type, the current row will be marked to show that the binding has been updated, and the shortcut field will be updated based on the keys entered.

 

If you made a mistake, you can press Backspace to clear a single key combination, or Delete to reset that binding to the original value it had when the widget was opened.

Commands can be either a single 'key chord'; for example, Ctrl+Alt+F, or also to a sequence of keys, as in Ctrl+X Ctrl+F.

You can also filter, based on the names of commands, by typing within the Filter... search box at the top left, to more easily find commands of interest:

After you've updated the bindings to your liking, click Apply and the shortcuts will be applied to the current session and saved for future sessions.

Handling Conflicts

By default, RStudio application command bindings will override editor command bindings. If an editor command and an RStudio command are both bound to the same key sequence, the RStudio command will take precedence and the editor command will not be executed. Editor commands that are masked by an RStudio command will be crossed out and have a small icon showing the masking command:

If two commands are bound to the same key sequence, then that conflict will be highlighted and displayed in yellow.

Saving and Loading

The RStudio keybindings are saved as JSON files in the directory ~/.R/rstudio/keybindings/ -- you can find the bindings for the editor and RStudio itself at:

RStudio 1.2 and prior

~/.R/rstudio/keybindings/rstudio_commands.json
~/.R/rstudio/keybindings/editor_commands.json

RStudio 1.3+ (Windows)

~/AppData/Roaming/RStudio/keybindings/rstudio_bindings.json
~/AppData/Roaming/RStudio/keybindings/editor_bindings.json

RStudio 1.3+ (MacOS/Linux)

~/.config/rstudio/keybindings/rstudio_bindings.json
~/.config/rstudio/keybindings/editor_bindings.json

 


Questions? Comments? Suggestions? Please get in touch at RStudio Support.

-Kevin

Comments

  • Avatar
    Gregory Dougherty

    How do I set a keybinding for a menu command? IOW I want F2 to do Cut, F3 to do Copy, and F4 to do Paste. I want to continue to allow cmd-X/C/V to continue to work as well. Is this possible in RStudio?

  • Avatar
    Kevin Ushey

    Hi Gregory,

    We currently don't allow users to rebind Cut / Copy / Paste, primarily due to some difficulties in getting this to work cross-platform and cross-browser. I'll see if this is something we can accommodate this in a future release.

    Thanks,
    Kevin

  • Avatar
    Alain Content

    Is it possible to assign shortcuts to user scripts ?

  • Avatar
    Alexander Martin Loewi

    I haven't been able to get Ctrl+P, "Move Upwards One Line," to work (an extremely important command to me, with bad wrist problems, and heavily dependent on keyboard navigation). I re-assigned Jump Between Brackets (which masks Ctrl+P), and then it gets un-crossed-out just fine -- but the command itself still doesn't work, even though it shows up in the .json. OTHER remappings are okay -- I reassigned Ctrl+G to be "Go To Line ..." and had no problems. Any help would be greatly appreciated.
    Best,

  • Avatar
    Michał Bojanowski

    Oh yes! Thank you for that!

    The following RStudio keyboard shortcuts are not usable when writing in Polish: Ctrl+Alt+[a,c,e,n,o,s,z,x] as AltGr = Ctrl + LeftAlt. See https://en.wikipedia.org/wiki/AltGr_key#Polish, and also google-translated Polish version https://pl.wikipedia.org/wiki/AltGr

  • Avatar
    Kevin Ushey

    Hi Alain,

    Mapping keyboard shortcuts to user scripts is something we have in the pipeline, but we haven't yet completed that work. Stay tuned!

    Best,
    Kevin

  • Avatar
    Kevin Ushey

    Hi Alexander,

    Thanks for reporting! This is a bug, and it should be fixed in the latest daily versions of RStudio -- if you have a chance, would you be willing to give it a try?

    https://dailies.rstudio.com/

    Alternatively, you can try turning on Emacs keybindings (available at Tools -> Global Options... -> Code -> Editing, which should ensure that Ctrl+P is appropriately mapped.

    Thanks,
    Kevin

  • Avatar
    Alexander Martin Loewi

    Hi Kevin,

    Thanks a ton for the help.

    In the new build I can use Ctrl+P fine, but suddenly 'Up' doesn't work, and I only have one spot to map Move Upwards (instead of two from an earlier build, which allowed both Up AND Ctrl+P).

    But Emacs mode works great (thanks for the tip), and it plays well with the other custom bindings.

    Thanks again -- I've been waiting for this feature for a long time.

  • Avatar
    Kevin Ushey

    Hi Alexander,

    Thanks for the bug report! I'll see what's going on and whether we can improve the situation here. Worst case scenario, you should be able to reset your keybindings (Ctrl-P is a default 'fall-back' keybinding for move up) so it should be restored following that (after which you can move 'jumpToMatching' out of the way).

    Best,
    Kevin

  • Avatar
    Valerio Biscione

    Hi Kevin,
    Is there any way to customize debugging shortcut?

  • Avatar
    Kevin Ushey

    Hi Valerio,

    Unfortunately, the debugging shortcuts are not yet customizable -- I've filed an issue for our development team and we'll see what we can do down the road.

    Best,
    Kevin

  • Avatar
    Gregory Dougherty

    Hi Kevin,

    Any news on getting Cut Copy Paste support? That's one of my absolute "must haves" for a development environment, so I'm really hoping RStudio can add it.

    Thank you,
    Greg

  • Avatar
    Filipescorrea

    Hi Kevin,

    After a while all my keyboard shortcuts stopped to work. I didn't do anything to change any configuration. Could it be any bug with the new released version? I have tryied to reinstall RStudio but I kept with the same problem, even after erasing the all the files in "%localappdata%\RStudio-Desktop".

    Best,

    Filipe

    Edited by Filipescorrea
  • Avatar
    robertob

    Is the ask by @Valerio above pertaining to Debug menu options?

    If so then i 2nd that ask because i wanted to customize all the debug run keyboard shortcuts to align with my vstudio experience so i could move between vstudio and rstudio using same debugging keys.

    I'm finding i cannot customize any of those menu options in order to achieve that result.  If it makes a difference i would be fine if initially support for this was provided by having to manually add entries %userprofile%\Documents\.R\rstudio\keybindings | editor_bindings.json or rstudio_bindings.json

    Also any work on the backlog to have keyboard shortcut customizations displayed in menus after you restart rstudio so you are shown current keyboard shortcuts in effect and not the defaults?

    Edited by robertob
  • Avatar
    robertob

    fyi

    with my windows 10 environment i was looking for customized keyboard shortcut settings under %appdata%/Rstudio and %localappdata%/RStudio-Desktop and couldn't find any rstudio_commands.json or editor_commands.json files there.  

    i did find them both under %userprofile%\Documents\.R\rstudio\keybindings.

    Edited by robertob
  • Avatar
    matthewsigal

    I am trying to set a keyboard shortcut for File -> New File -> R Markdown document, but I can't seem to find the listing in the Keyboard Shortcuts dialogue box? Is there any way to set this shortcut?

  • Avatar
    lincolnfrias

    Hi,

    Is it possible to use a shortcut to minimize panels?

    By the way, the shortcuts are great and it awesome to be able to customize them. Congrats!

    Edited by lincolnfrias
  • Avatar
    pmmwaniki06

    Hi,
    Is it possible to create an editor shortcut for inserting %in% into ones code similar to how %>% is inserted with Ctrl-Shift-M

  • Avatar
    GoDa

    Hi,

    I recently updated RStudio for Windows via the RStudio website mainly due to interest in the new features of the most recent version 0.99.878. Unfortunaly after the installation some important hotkeys behave different in the source editor, while they still work in the Console. I.e.

    `Ctrl` + `S` starts an "isearch"
    `Ctrl` + `V` jumps to the end of the document

    When I enter `Ctrl` + `X` + (`S` or `V`) the hotkeys work as they should. The hotkeys can be costumized, however when I open the Keyboard Sortcuts dialog it shows me the settings for the hotkeys. Also the cursor has turned to a shiny green rectangle (`insert` isn't activated).

    The problems remains after switching the project. Also reinstalling Rstudio 0.99.878 didn't work out. Might I have accidently activated a special editor setting, of which I'm not aware yet?

    Thanks,
    David

  • Avatar
    Kevin Ushey

    Hi David,

    It sounds like you've activated Emacs mode -- try going to Tools -> Global Options... -> Code, and change Keybindings from Emacs back to Default.

    Thanks,
    Kevin

  • Avatar
    Kevin Ushey

    Hi pmmwaniki06,

    It's now possible to do this through the RStudio Addins system -- please see https://rstudio.github.io/rstudioaddins/ for more details; in particular, this is an addin that implements the behavior you're looking for:

    https://github.com/rstudio/addinexamples/blob/master/R/insertInAddin.R

    Best,
    Kevin

  • Avatar
    GoDa

    Hi Kevin,

    thanks a lot that was indeed what happend.

    All the best,
    David

  • Avatar
    Michaël Gras

    Hi Kevin,

    I would like to use F5 instead of ctrl+R to run my R code in RStudio. I guess it could be done by a modification of ctrl+R or by creating an alias of ctrl+R. Would you have any idea how I can do that?

    Thanks in advance for your help.

    Michaël

  • Avatar
    Kevin Ushey

    Hi Michael,

    There is a command called 'Run Current Line or Selection', which is normally bound to 'Cmd + Enter'. You should be able to rebind this to F5, and then typing F5 will executed that command.

    Best,
    Kevin

  • Avatar
    Michaël Gras

    Hi Kevin,

    Thanks for your help, it's done and it works perfectly well.

    Regards

    Michaël

  • Avatar
    Brice Leclère

    Hi Kevin,

    Is it possible to change the '<-' shortcut (alt-)? It interferes with my keyboard layout (bépo, a French equivalent to dvorak) and I cannot type an underscore without switching to another kb layout first.

    Many thanks in advance,
    Brice

  • Avatar
    Pierre Gramme

    Hi Kevin and the team,

    Maybe a dumb question: on Ubuntu, how can I differentiate between Ctrl and Cmd keys?

    I would like to use the standard Ctrl+Y shortcut for "Redo". But when I type it, it gets interpreted as "Insert Yanked Text" (as I guess from the shortcut quick ref).

    Can I disable this shortcut for "Insert Yanked Text" even if it's not listed in the dialog box? Can I assign Ctrl+Y to "Redo"?

    Thanks
    Pierre

  • Avatar
    Kevin Ushey

    Hi Pierre,

    This is an unfortunate limitation in the current version of RStudio, as the various 'yank' commands are hard-coded to these bindings (and have been for some time). We plan to resolve this for the next release.

    Thanks,
    Kevin

  • Avatar
    Pierre Gramme

    Ok, no problem. Thanks for the explanation!
    And about the difference between Ctrl and Cmd: is it only available on a Mac?

    Pierre

  • Avatar
    Kevin Ushey

    Hi Pierre,

    The nomenclature here is a bit confusing, unfortunately -- within the keyboard shortcuts dialog, 'Cmd' implies either the 'Ctrl' or 'Meta' keys (for non-Mac systems). We'll look into improving the display of information here.

    Best,
    Kevin