Support

Customizing Keyboard Shortcuts

Follow

Customizing Keyboard Shortcuts

You can now customize keyboard shortcuts in RStudio -- 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:

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

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

-Kevin

Comments

  • Avatar
    Ochado

    Thanks for the article, but how do I add a custom shortcut for inserting the assignment operator

  • Avatar
    Kevin Ushey

    Hi Ochado,

    Unfortunately, this keybinding is currently hardcoded and hence not rebindable -- we intend to correct this for the next release.

    Best,
    Kevin

  • Avatar
    Ochado

    OK; thanks. I'll be looking forward to that update.

  • Avatar
    Ochado

    Any update on adding a custom shortcut for inserting the assignment operator? Which next release was this scheduled for? I'm on 0.99.902 but I still can't find how to do this.

  • Avatar
    soren.merser

    As I haven't been able to find the correct hotkey I wonder if there's a way to invoke isearch / reverse-isearch without enabling emacs keybinding (which makes the cursor green)

    Edited by soren.merser
  • Avatar
    Kevin Ushey

    Hi Ochado,

    Sorry for the delayed response. This should now be available now in the current RStudio preview release -- can you download it and give it a shot?

    https://www.rstudio.com/products/rstudio/download/preview/

    Thanks,
    Kevin

  • Avatar
    Kevin Ushey

    Hi Soren,

    The 'isearch' functionality is currently only implemented when Emacs keybindings are active -- I'll add the ability to enable them in other modes as a feature request.

    Thanks,
    Kevin

  • Avatar
    soren.merser

    Hi Kevin

    Thanks! 


    Best Soren

    Edited by soren.merser
  • Avatar
    Ochado

    @Kevin Ushey: The new key binding to replace the assignment operator works beautifully! Thanks a lot!

    Edited by Ochado
  • Avatar
    Daniel Possenriede

    Hi Kevin,

    F1 opens the help file and F2 opens the function definition of the object on which the cursor is located. Would it be possible to create a Keyboard Shortcut in the same vain for objects that opens the View window or shows me a glimpse, str, head, etc. of the object.

    In other words: I have a data.frame df, I set the cursor on the "df" in the source or console window, I press a Keyboard Shortcut and R opens the View window with that data.frame or glimpse(df) etc.

    Is that possible?

    Thanks!
    Daniel

  • Avatar
    Kevin Ushey

    Hi Daniel,

    Thanks; you are indeed right. One way this could be handled would be with a custom RStudio addin -- see e.g.

    https://rstudio.github.io/rstudioaddins/

    for details on how this could be accomplished. Nonetheless, we'll see if we can add support for this natively in RStudio.

    Thanks,
    Kevin

  • Avatar
    Kmbell56

    rstudio addins is not a very user friendly or fast option. A very common case is to input some user-defined text at the cursor - this would be a very powerful thing to add natively.

  • Avatar
    Tim Courtney

    Is there a way to assign multiple shortcuts to one action? I'd like to have a homerow-accessible hotkey for moving down a line while I'm writing, but I don't want to lose the use of the down arrow for when I'm scrolling.
    A "start new line below this one" function would also be really great, like enter but without moving anything right of the cursor to the new line. As is, it's not very helpful to add closing " and ) because you have to type them or move past them to get to the next line anyway. That's my real motivation for a second down key.

  • Avatar
    Naveen Srivastava

    Hi Kevin
    Is there any possibility to play with the shortcuts keys.
    Like I want to run an R script from another R Script, but I am having issue in running the script through script.
    any help is highly appreciated.

    Regards
    Naveen Srivastava