Add keybinding for %<>% magrittr pipe operator

I know you can modify the keybindings in Rstudio going to "Tools > Modify Keyboard Shortcuts"
But i use %<>% pipe operator too much and need to assign it to a keybinding (similar to Ctrl + Shift + M)

A workaround is to create a snippet for such pipe (Tools > Global options > Code > Edit Snippets):

snippet p
	${1:object} %<>% ${0}

But I rather assing a keybinding if possible. is there any way of creating such shortcut?

1 Like

Yes.

I have a package that has some pre-made key-bidnings and allows the user to define their own. Please give it a try: https://github.com/WinVector/addinexamplesWV.

2 Likes

Just to generalize from John's example (which is great, btw), add-ins allow you to create keybindings for whatever it is that add-in does (whether it be inserting a pipe, as in this case, running code, etc.).

Jozef Hajnala wrote a post the other day that included a nice little gif of how to add a shortcut for an add-in (again, John describes this exact same thing in addinexamplesWV, this is just gravy)!

4 Likes

Thanks a lot! I will try the addin approach