%>% key binding / keyboard shortcut in Rstudio

2019-01-23 23:32发布

问题:

I've been experimenting quite a bit with the increasingly popular %>% operator from the magrittr package.

I've used it enough that I've set a keyboard shortcut to save me typing:

shift+command+. instead of space, shift+5, shift+., shift+5, space.

This is great in SublimeTetxt2 but Rstudio does not allow services it does not work if I'm working within Rstudio projects.

So my question is:

Can you define text-inserting key-bindings or shortcuts within Rstudio?

This would be exactly synonymous with the alt+- binding for the assignment <- operator that is oxygen to the otter.

If someone could point me to where the shortcuts are coded in the github repo so I could "hack" my own, I suppose this would be a useful start.

https://github.com/rstudio/rstudio

回答1:

Just noticed that RStudio v0.98.1079 has shift+command+M mapped for the %>% operator. You can check out the other keyboard shortcuts within RStudio by clicking at the Help tab or by entering alt+shift+K.



回答2:

For stuff like that you can use autohotkey. it is an external windows program but can do pretty much anything including hotkeys that type stuff and acronyms that are replaced by stuff you want



回答3:

I think the answer to your question is "Not currently, but it's on RStudio's to-do list" (see: this and this).

If you want to hack it yourself, it looks like this is where you'd do it (GitHub: rstudio / src / gwt / src / org / rstudio / core / rebind / command / ShortcutsEmitter.java).

Also, it looks like shortcuts are managed here (GitHub: rstudio / src / gwt / src / org / rstudio / core / client / command).



回答4:

R studio Preview (v0.99.671) now supports keybuindings customization. It also has a bunch of other nice improvements, give it a try:

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