There are only a few basic constructs allowed in the Readline init file. Blank lines are ignored. Lines beginning with a ‘#’ are comments. Lines beginning with a ‘$’ indicate conditional constructs (see Conditional Init Constructs). Other lines denote variable settings and key bindings.
You can modify the run-time behavior of Readline by
altering the values of variables in Readline
set command within the init file.
The syntax is simple:
set variable value
Here, for example, is how to
change from the default Emacs-like key binding to use
vi line editing commands:
set editing-mode vi
Variable names and values, where appropriate, are recognized without regard to case. Unrecognized variable names are ignored.
Boolean variables (those that can be set to on or off) are set to on if the value is null or empty, on (case-insensitive), or 1. Any other value results in the variable being set to off.
A great deal of run-time behavior is changeable with the following variables.
Controls what happens when Readline wants to ring the terminal bell. If set to ‘none’, Readline never rings the bell. If set to ‘visible’, Readline uses a visible bell if one is available. If set to ‘audible’ (the default), Readline attempts to ring the terminal’s bell.
If set to ‘on’, Readline attempts to bind the control characters treated specially by the kernel’s terminal driver to their Readline equivalents.
The string to insert at the beginning of the line when the
insert-comment command is executed. The default value
The number of screen columns used to display possible matches when performing completion. The value is ignored if it is less than 0 or greater than the terminal screen width. A value of 0 will cause matches to be displayed one per line. The default value is -1.
If set to ‘on’, Readline performs filename matching and completion in a case-insensitive fashion. The default value is ‘off’.
If set to ‘on’, and completion-ignore-case is enabled, Readline treats hyphens (‘-’) and underscores (‘_’) as equivalent when performing case-insensitive filename matching and completion.
The length in characters of the common prefix of a list of possible completions that is displayed without modification. When set to a value greater than zero, common prefixes longer than this value are replaced with an ellipsis when displaying possible completions.
The number of possible completions that determines when the user is
asked whether the list of possibilities should be displayed.
If the number of possible completions is greater than this value,
Readline will ask the user whether or not he wishes to view
them; otherwise, they are simply listed.
This variable must be set to an integer value greater than or equal to 0.
A negative value means Readline should never ask.
The default limit is
If set to ‘on’, Readline will convert characters with the eighth bit set to an ASCII key sequence by stripping the eighth bit and prefixing an ESC character, converting them to a meta-prefixed key sequence. The default value is ‘on’.
If set to ‘On’, Readline will inhibit word completion.
Completion characters will be inserted into the line as if they had
been mapped to
self-insert. The default is ‘off’.
editing-mode variable controls which default set of
key bindings is used. By default, Readline starts up in Emacs editing
mode, where the keystrokes are most similar to Emacs. This variable can be
set to either ‘emacs’ or ‘vi’.
When set to ‘on’, on operating systems that indicate they support it, readline echoes a character corresponding to a signal generated from the keyboard. The default is ‘on’.
When set to ‘on’, Readline will try to enable the application keypad when it is called. Some systems need this to enable the arrow keys. The default is ‘off’.
When set to ‘on’, Readline will try to enable any meta modifier key the terminal claims to support when it is called. On many terminals, the meta key is used to send eight-bit characters. The default is ‘on’.
If set to ‘on’, tilde expansion is performed when Readline attempts word completion. The default is ‘off’.
If set to ‘on’, the history code attempts to place the point (the
current cursor position) at the
same location on each history line retrieved with
next-history. The default is ‘off’.
Set the maximum number of history entries saved in the history list. If set to zero, the number of entries in the history list is not limited.
This variable can be set to either ‘on’ or ‘off’. Setting it to ‘on’ means that the text of the lines being edited will scroll horizontally on a single screen line when they are longer than the width of the screen, instead of wrapping onto a new screen line. By default, this variable is set to ‘off’.
If set to ‘on’, Readline will enable eight-bit input (it
will not clear the eighth bit in the characters it reads),
regardless of what the terminal claims it can support. The
default value is ‘off’. The name
meta-flag is a
synonym for this variable.
The string of characters that should terminate an incremental search without subsequently executing the character as a command (see Searching). If this variable has not been given a value, the characters ESC and C-J will terminate an incremental search.
Sets Readline’s idea of the current keymap for key binding commands.
keymap names are
vi is equivalent to
emacs-standard. The default value is
The value of the
editing-mode variable also affects the
If set to ‘on’, completed directory names have a slash appended. The default is ‘on’.
This variable, when set to ‘on’, causes Readline to display an asterisk (‘*’) at the start of history lines which have been modified. This variable is ‘off’ by default.
If set to ‘on’, completed names which are symbolic links
to directories have a slash appended (subject to the value of
The default is ‘off’.
This variable, when set to ‘on’, causes Readline to match files whose names begin with a ‘.’ (hidden files) when performing filename completion. If set to ‘off’, the leading ‘.’ must be supplied by the user in the filename to be completed. This variable is ‘on’ by default.
If set to ‘on’, menu completion displays the common prefix of the list of possible completions (which may be empty) before cycling through the list. The default is ‘off’.
If set to ‘on’, Readline will display characters with the eighth bit set directly rather than as a meta-prefixed escape sequence. The default is ‘off’.
If set to ‘on’, Readline uses an internal
to display a screenful of possible completions at a time.
This variable is ‘on’ by default.
If set to ‘on’, Readline will display completions with matches sorted horizontally in alphabetical order, rather than down the screen. The default is ‘off’.
If set to ‘on’, Readline will undo all changes to history lines
before returning when
accept-line is executed. By default,
history lines may be modified and retain individual undo lists across
readline. The default is ‘off’.
This alters the default behavior of the completion functions. If set to ‘on’, words which have more than one possible completion cause the matches to be listed immediately instead of ringing the bell. The default value is ‘off’.
This alters the default behavior of the completion functions in a fashion similar to show-all-if-ambiguous. If set to ‘on’, words which have more than one possible completion without any possible partial completion (the possible completions don’t share a common prefix) cause the matches to be listed immediately instead of ringing the bell. The default value is ‘off’.
If set to ‘on’, this alters the default completion behavior when inserting a single match into the line. It’s only active when performing completion in the middle of a word. If enabled, readline does not insert characters from the completion that match characters after point in the word being completed, so portions of the word following the cursor are not duplicated. For instance, if this is enabled, attempting completion when the cursor is after the ‘e’ in ‘Makefile’ will result in ‘Makefile’ rather than ‘Makefilefile’, assuming there is a single possible completion. The default value is ‘off’.
If set to ‘on’, a character denoting a file’s type is appended to the filename when listing possible completions. The default is ‘off’.
The syntax for controlling key bindings in the init file is simple. First you need to find the name of the command that you want to change. The following sections contain tables of the command name, the default keybinding, if any, and a short description of what the command does.
Once you know the name of the command, simply place on a line in the init file the name of the key you wish to bind the command to, a colon, and then the name of the command. There can be no space between the key name and the colon – that will be interpreted as part of the key name. The name of the key can be expressed in different ways, depending on what you find most comfortable.
In addition to command names, readline allows keys to be bound to a string that is inserted when the key is pressed (a macro).
keyname is the name of a key spelled out in English. For example:
Control-u: universal-argument Meta-Rubout: backward-kill-word Control-o: "> output"
In the above example, C-u is bound to the function
M-DEL is bound to the function
C-o is bound to run the macro
expressed on the right hand side (that is, to insert the text
‘> output’ into the line).
A number of symbolic character names are recognized while processing this key binding syntax: DEL, ESC, ESCAPE, LFD, NEWLINE, RET, RETURN, RUBOUT, SPACE, SPC, and TAB.
keyseq differs from keyname above in that strings denoting an entire key sequence can be specified, by placing the key sequence in double quotes. Some GNU Emacs style key escapes can be used, as in the following example, but the special character names are not recognized.
"\C-u": universal-argument "\C-x\C-r": re-read-init-file "\e[11~": "Function Key 1"
In the above example, C-u is again bound to the function
universal-argument (just as it was in the first example),
‘C-x C-r’ is bound to the function
and ‘ESC [ 1 1 ~’ is bound to insert
the text ‘Function Key 1’.
The following GNU Emacs style escape sequences are available when specifying key sequences:
an escape character
", a double quotation mark
', a single quote or apostrophe
In addition to the GNU Emacs style escape sequences, a second set of backslash escapes is available:
the eight-bit character whose value is the octal value nnn (one to three digits)
the eight-bit character whose value is the hexadecimal value HH (one or two hex digits)
When entering the text of a macro, single or double quotes must be used to indicate a macro definition. Unquoted text is assumed to be a function name. In the macro body, the backslash escapes described above are expanded. Backslash will quote any other character in the macro text, including ‘"’ and ‘'’. For example, the following binding will make ‘C-x \’ insert a single ‘\’ into the line: