In practice I prefer to write R codes with Notepad++ and NppToR, where you can use the default shortcut keys to achieve the following functions:
F8: P