Next: Conditional Init Constructs, Up: Readline Init File
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.
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.
The bind -V command lists the current Readline variable names
and values. See Bash Builtins.
A great deal of run-time behavior is changeable with the following variables.
bell-stylebind-tty-special-charscomment-begininsert-comment command is executed. The default value
is "#".
completion-ignore-casecompletion-query-items100.
convert-metadisable-completionself-insert. The default is ‘off’.
editing-modeediting-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’.
enable-keypadexpand-tildehistory-preserve-pointprevious-history
or next-history. The default is ‘off’.
horizontal-scroll-modeinput-metameta-flag is a
synonym for this variable.
isearch-terminatorskeymapkeymap names are
emacs,
emacs-standard,
emacs-meta,
emacs-ctlx,
vi,
vi-move,
vi-command, and
vi-insert.
vi is equivalent to vi-command; emacs is
equivalent to emacs-standard. The default value is emacs.
The value of the editing-mode variable also affects the
default keymap.
mark-directoriesmark-modified-linesmark-symlinked-directoriesmark-directories).
The default is ‘off’.
match-hidden-filesoutput-metapage-completionsmore-like pager
to display a screenful of possible completions at a time.
This variable is ‘on’ by default.
print-completions-horizontallyshow-all-if-ambiguousshow-all-if-unmodifiedvisible-statsOnce 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).
The bind -p command displays Readline function names and
bindings in a format that can put directly into an initialization file.
See Bash Builtins.
Control-u: universal-argument
Meta-Rubout: backward-kill-word
Control-o: "> output"
In the above example, C-u is bound to the function
universal-argument,
M-DEL is bound to the function backward-kill-word, and
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.
"\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 re-read-init-file,
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:
In addition to the gnu Emacs style escape sequences, a second set of backslash escapes is available:
\a\b\d\f\n\r\t\v\nnn\xHHWhen 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:
"\C-x\\": "\\"