Go to the previous, next section.

Readline Init Syntax

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 section Conditional Init Constructs). Other lines denote variable settings and key bindings.

Variable Settings
You can change the state of a few variables in Readline by using the set command within the init file. Here is how you would specify that you wish to use vi line editing commands:

set editing-mode vi

Right now, there are only a few variables which can be set; so few, in fact, that we just list them here:

editing-mode
The editing-mode variable controls which editing mode you are using. 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.

horizontal-scroll-mode
This variable can be set to either On or Off. Setting it to On means that the text of the lines that you edit 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.

mark-modified-lines
This variable, when set to On, says to display an asterisk (`*') at the start of history lines which have been modified. This variable is off by default.

bell-style
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.

comment-begin
The string to insert at the beginning of the line when the vi-comment command is executed. The default value is "#".

meta-flag
If set to on, Readline will enable eight-bit input (it will not strip the eighth bit from the characters it reads), regardless of what the terminal claims it can support. The default value is off.

convert-meta
If set to on, Readline will convert characters with the eigth bit set to an ASCII key sequence by stripping the eigth bit and prepending an ESC character, converting them to a meta-prefixed key sequence. The default value is on.

output-meta
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.

completion-query-items
The number of possible completions that determines when the user is asked whether he wants to see the list of possibilities. 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. The default limit is 100.

keymap
Sets Readline's idea of the current keymap for key binding commands. Acceptable keymap 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.

show-all-if-ambiguous
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.

expand-tilde
If set to on, tilde expansion is performed when Readline attempts word completion. The default is off.

  • Key Bindings The syntax for controlling key bindings in the init file is simple. First you have to know the name of the command that you want to change. The following pages contain tables of the command name, the default keybinding, and a short description of what the command does.

    Once you know the name of the command, simply place the name of the key you wish to bind the command to, a colon, and then the name of the command on a line in the init file. The name of the key can be expressed in different ways, depending on which is most comfortable for you.

    keyname: function-name or 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 universal-argument, 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).

    "keyseq": function-name or macro
    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 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 escape sequences are available when specifying key sequences:

    \C-
    control prefix
    \M-
    meta prefix
    \e
    an escape character
    \\
    backslash
    \"
    "
    \'
    '

    When entering the text of a macro, single or double quotes should be used to indicate a macro definition. Unquoted text is assumed to be a function name. Backslash will quote any character in the macro text, including " and '. For example, the following binding will make C-x \ insert a single \ into the line:

    "\C-x\\": "\\"
    

  • Go to the previous, next section.