Chapter 17 Appendix C The command-line editor
When the GNU readline library is available at the time R is configured for compilation under UNIX, an inbuilt command line editor allowing recall, editing and re-submission of prior commands is used. Note that other versions of readline exist and may be used by the inbuilt command line editor: this used to happen on macOS.
It can be disabled (useful for usage with ESS 27) using the startup option –no-readline.
Windows versions of R have somewhat simpler command-line editing: see ‘Console’ under the ‘Help’ menu of the GUI, and the file README.Rterm for command-line editing under
When using R with GNU28 readline capabilities, the functions described below are available, as well as others (probably) documented in
man readline or
info readline on your system.
Many of these use either Control or Meta characters. Control characters, such as Control-m, are obtained by holding the
CTRL down while you press the
m key, and are written as C-m below. Meta characters, such as Meta-b, are typed by holding down
META29 and pressing
b, and written as M-b in the following. If your terminal does not have a
META key enabled, you can still type Meta characters using two-character sequences starting with ESC. Thus, to enter M-b, you could type
b. The ESC character sequences are also allowed on terminals with real Meta keys. Note that case is significant for Meta characters.
Some but not all versions30 of readline will recognize resizing of the terminal window so this is best avoided.
C.2 Editing actions
The R program keeps a history of the command lines you type, including the erroneous lines, and commands in your history may be recalled, changed if necessary, and re-submitted as new commands. In Emacs-style command-line editing any straight typing you do while in this editing phase causes the characters to be inserted in the command you are editing, displacing any characters to the right of the cursor. In vi mode character insertion mode is started by M-i or M-a, characters are typed and insertion mode is finished by typing a further
ESC. (The default is Emacs-style, and only that is described here: for vi mode see the readline documentation.)
RET command at any time causes the command to be re-submitted.
Other editing actions are summarized in the following table.
C.3 Command-line editor summary
Command recall and vertical motion
Go to the previous command (backwards in the history).
Go to the next command (forwards in the history).
- C-r text
Find the last command with the text string in it. This can be cancelled by
C-g(and on some versions of R by
On most terminals, you can also use the up and down arrow keys instead of C-p and C-n, respectively.
Horizontal motion of the cursor
Go to the beginning of the command.
Go to the end of the line.
Go back one word.
Go forward one word.
Go back one character.
Go forward one character.
On most terminals, you can also use the left and right arrow keys instead of C-b and C-f, respectively.
Editing and re-submission
Insert text at the cursor.
- C-f text
Append text after the cursor.
Delete the previous character (left of the cursor).
Delete the character under the cursor.
Delete the rest of the word under the cursor, and “save” it.
Delete from cursor to end of command, and “save” it.
Insert (yank) the last “saved” text here.
Transpose the character under the cursor with the next.
Change the rest of the word to lower case.
Change the rest of the word to upper case.
Re-submit the command to R.
RET terminates the command line editing sequence.
The readline key bindings can be customized in the usual way via a ~/.inputrc file. These customizations can be conditioned on application
R, that is by including a section like
$if R "\C-xd": "q('no')\n" $endif