Shortcuts in R under Unix from the readline library

Under Unix you can use in R the the advanced features for command editing and command history that the GNU Readline Library provides.

Both Emacs and vi editing modes are available and the Emacs-like keybindings are installed by default. Here some Emacs keybindings that also work in R (from the documentation of the GNU Readline Library):

Copy and Paste:
Ctrl-u Cut from the cursor to the beginning of the line.
Ctrl-k Cut from the cursor to the end of the line.
Ctrl-w Cut from the cursor to the start of the word.
Ctrl-y Pastes text from the clipboard.
Alt-y Rotate the kill-ring, and paste the new top. You can only do this if the prior command was Ctrl-y or Alt-y.

Moving:
Ctrl-a Move to the start of the line.
Ctrl-e Move to the end of the line.
Alt-b Move back one word.
Alt-f Move forward one word.
Ctrl-b Move back one character.
Ctrl-f Move forward one character.

Undo:
Ctrl-_ Undo the last changes.
Alt-r Undo all changes to the line.

Miscellaneous:
Ctrl-l Clear the screen leaving the current line at the top of the screen.

History:
Ctrl-r Incremental reverse search of history.
Alt-p Non-incremental reverse search of history.

If you want to use the vi-mode just press Ctrl+Alt+j and you can use the usual vi modes and commands (for example take a look at this vi-editing-mode-cheat-sheet).

If you want to start in the vi mode by default, put the following line in your ~/.inputrc (which of course will also effect your bash etc.):

set editing-mode vi

Leave a Reply

Your email address will not be published. Required fields are marked *