^P
ulling previous commands and modifying them either for correction or revision.
It is used by several programs including bash, ftp, bc, gdb, MySQL
and the perl debugger(perl -d
).
These keystrokes are used when the line editor is set to emacs
, the default.
(In bash
, to use vi
keystrokes issue: set -o vi
)
shift
and control
are pressed and held before the next key is pressed.
alt
is a "lead-in" and M
odifies action of the next key pressed. Many terminal emulators use ␛.
Additional "special" keys: DEL
(delete, sometimes engraved ⇐ ),
SPACE
, RET
, and TAB
. LF
(linefeed) use ^j
.
The RET
key may be labeled Return
or Enter
.
When you are satisfied with the line, press RET
(the cursor need not be at the end of the line) the entire line is sent.
As you type the character appears where the cursor was, and the cursor moves to the right.
If you mistype a character, use the "erase" character to back up and delete the mistyped character. (defaulted to DEL
by stty
).
If you mistype a character, and don't notice until you have typed several other characters.
When adding text in the middle of a line, characters to the right of the cursor are "pushed over" to make room for the text
that you have inserted. When deleting text before the cursor, characters to the right of the cursor are "pulled back".
type ^b
(or ← ) to move the cursor back to the left, and then correct your mistake,
then move the cursor forward ( or → ) to the right with ^f
.
DEL or Backspace | Delete the character to the left of the cursor.
(DEL may be set to delete the character underneath the cursor)
|
^d | Delete the character under the cursor. |
^u or ^_ or ^x | Undo the last edit. Works repeatedly. |
Use ^p
to pull a command from history.
^a | to the start of the line. | ^e | to the end of the line. |
␛b | backward a word. | ␛f | forward a word
a word is composed of letters and digits.
|
^b | back one character. | ^f | forward one character. |
^l | Clear the screen, redisplaying the current line at the top. |
Usually control keystrokes operate on characters while alt keystrokes operate on words.
K
illing text deletes it and saves it for later use,
usually by y
anking (re-inserting) it back into the line, perhaps at a different place.killed text is appended to a kill-ring all of which is retrieved when yanked back.
The kill ring is not line specific; and can be y
anked into another line.
␛DEL | back to the start of the current word, if between words, to the start of the previous word. |
^w | to the previous whitespace. This is different than ␛DEL because the word boundaries differ. |
␛d | to the end of the current word, if between
words, to the end of the next word. |
^k | to the end of the line. |
^y | Yank the most recently killed text into the buffer at the cursor. |
␛y | Rotate the kill-ring, and yank the new top. only if the prior command is ^y or ␛y .
|
nn
before the command to specify a repeat count. readline
displays (arg: nn)
at the beginning of the line, removing it when command is complete.
A negative argument reverses the direction of the action.
For example, to kill text back to the start of the line, type ␛-^k
( instead of to the end of the line).
To delete the next 10 characters on the line ␛10^d
.
^r
begins an incremental search in the reverse direction.readline
displays (reverse-i-search)`'
at the beginning of the line.`
and the '
.^r
searchs again with the same string.
^s
searches forward through the history if you have gone back too far.
^g
aborts the search and restores the original line.
RET
will terminate the search and execute that command.
A control movement command (example: ^b
) will terminate the search.
p
invokes a non-incremental search throught the previous enrties in the history which
accepts the entire search string before searching the history. readline
clears the line and displays a :
. Enter a string to search for and then ␛.readline
recalls the matching entry from the history.
Readline defaults to Emacs-like keybindings (using control characters and ␛)
To use a different keybindings add commands to file named in the environment variable INPUTRC
,
default ~/.inputrc
or the system wide default /etc/inputrc
.
The ^x ^r
command re-reads the init file, incorporating any changes.
#
are comments. $
Conditional Init Constructs.
Variable Settings
The syntax is :
set variable value
Example: change from Emacs-like key binding to vi :
set editing-mode vi
Names and values are not case sensitive.
Unrecognized variable names are ignored.
Boolean variables are set ON
if set
to on
, 1
, null, empty.
In bash, bind -V
lists names and values.
comment-begin | string inserted at the beginning of the line when the insert-comment command is executed. default # .
|
bell-style |
audible default, sound the bell.none never sounds the bell. visible uses a visible bell if available (perhaps flash screen in inverse video). |
editing-mode | default set of key bindings. emacs or vi . Default emacs.
|
keymap | Sets the current keymap for key binding commands. keymap names areemacs , emacs-standard , emacs-alt , emacs-ctlx emacs is equivalent to emacs-standard . default emacs .
|
bind-tty-special-chars | ON : bind the control characters treated specially by the kernel's terminal driver to their Readline equivalents.
|
Completion keys | |
completion-ignore-case | ON : filename matching and completion is case insensitive. Default OFF
|
completion-query-items |
Maximun number of possible completions to display. If more user is prompted whether or not to view them . Negative don't ask. default 100 !That's a lot, like maybe 20 would be a better value(ed)
|
display-completions-horizontally | ON : display completions with matches
sorted horizontally in alphabetical orderOFF than down the screen. Default OFF .
|
disable-completion | ON : inhibit word completion.
Completion characters will be inserted into the line as if they had been mapped to self-insert . Default OFF .
|
show-all-if-ambiguous | Alters the default behavior of the completion functions. ON : words which have more than one possible completion are listed OFF : bell.
Default OFF .
|
show-all-if-unmodified | similar to show-all-if-ambiguous . ON : words which have more than one possible completion without any
possible partial completion (the possible completions don't share a common prefix) are listed OFF : bell.
Default OFF .
|
expand-tilde | ON : tilde expansion is performed with word completion to search the home directory. Default OFF .
|
page-completions | ON :
use an internal more -like pager to display a screenful of possible completions at a time. Default ON
|
visible-stats | ON : a character denoting a file's type is appended to the filename when listing possible completions. Default OFF .
|
enable-keypad | ON : enable the application keypad, may be needed to enable arrow keys. Default OFF .
|
history-preserve-point | ON : the history code attempts to place point at the
same location on each history line retrieved with previous-history
or next-history . default OFF .
|
horizontal-scroll-mode |
ON : text of the lines being edited will scroll
horizontally when longer than the width.OFF : wrapping onto a new line. Default OFF .
|
isearch-terminators | string that terminates
an incremental search without subsequently executing the character as a command (see Searching). Default ESC and ^J .
|
mark-directories | ON : completed directory names have a slash
appended. Default ON .
|
mark-symlinked-directories | ON : symbolic links to directories have a slash appended (subject to the value of mark-directories ).
Default OFF .
|
mark-modified-lines |
ON : display an asterisk (* ) at the start of history lines which have been modified. Default off .
|
match-hidden-files |
ON : match files whose names begin with a . (hidden files) when performing filename
completion, unless the leading . is supplied by the user in the filename to be completed. Default ON .
|
convert-alt | ON : convert characters with the eighth bit set, to an ASCII sequence by sending ␛ and stripping the eighth
bit, effectively converting them to a alt-prefixed key sequence. default ON .
|
input-alt | ON : enable eight-bit input ( eighth bit in the characters are not cleared ),regardless of what the terminal claims it can support. Default OFF . alt-flag is a synonym
|
output-alt |
ON : display characters with the eighth bit set directly rather than as a alt-prefixed escape sequence. Default OFF .
|
Key Bindings
In addition to command names, readline allows keys to be bound to a string that is inserted when the key is pressed ( macro).
In bash bind -p
displays Readline function names and
bindings in a format that can put directly into an initialization file.
keyname: function-name or macro keyname is the name of a key spelled out in English. For example: Control-u: universal-argument alt-Rubout: backward-kill-word Control-o: " output"
A number of symbolic character names are recognized while processing this key binding syntax:
| keyseq differs from keyname in that strings
denoting an entire key sequence are specified, by placing
the key sequence in double quotes. Some Emacs style key escapes can be used, but the special character names are not recognized.
"\^u": universal-argument "\^x\^r": re-read-init-file "\e[11~": "Function Key 1"
|
The following gnu Emacs style escape sequences are available when specifying key sequences:
\^ | control prefix |
\␛ | alt prefix |
\e | an escape character |
\\ | backslash |
\" | ", 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:
\a | alert (bell) |
\b | backspace |
\d | delete |
\f | form feed |
\n | newline |
\r | carriage return |
\t | horizontal tab |
\v | vertical tab |
\ nnn | the eight-bit character whose value is the octal value nnn (one to three digits) |
\x HH | 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 specifies 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
insert a single ^x
\\
into the line:
"\^x\\": "\\"
$if | allows bindings to be made based on the editing mode, the terminal being used, or the application. The text of the test extends to the end of the line; no characters are required to isolate it. |
$else | Commands in this branch of the $if directive are executed if the test fails.
|
$endif | terminates an $if command.
|
mode=vi|emacs | test whether in emacs or vi mode. This may be used in conjunction with the set keymap command, to set bindings in
the emacs-standard and emacs-ctlx keymaps only if
in emacs mode.
|
term= | term= include terminal-specific
key bindings, perhaps to bind the key sequences output by the terminal's function keys. The word on the right side of the = is tested against both the full name of the terminal and
the portion of the terminal name before the first - ,
allows sun to match both sun and sun-cmd , for instance.
|
application= | used to include
application-specific settings. Each program sets the application name, and you can test for it. This could be used to bind key sequences to functions useful for a specific program. For instance, the following command adds a key sequence that quotes the current or previous word in Bash: $if Bash # Quote the current or previous word "\^xq": "\eb\"\ef\"" $endif |
$include file |
# including bc, FTP, Bash, and GDB. # # to re-read the inputrc file use ^x ^r # Lines beginning with '#" are comments. # # include any systemwide bindings and variable assignments $include /etc/Inputrc # Set various bindings for emacs mode. set editing-mode emacs $if mode=emacs alt-Control-h: backward-kill-word Text after the function name is ignored # Arrow keys in ANSI mode "\␛[D": backward-char "\␛[C": forward-char "\␛[A": previous-history "\␛[B": next-history # # Arrow keys in 8 bit keypad mode (notice thee are commented out!) #"\␛\^OD": backward-char #"\␛\^OC": forward-char #"\␛\^OA": previous-history #"\␛\^OB": next-history # Arrow keys in 8 bit ANSI mode (notice thee are commented out!) #"\␛\^[D": backward-char #"\␛\^[C": forward-char #"\␛\^[A": previous-history #"\␛\^[B": next-history # Arrow keys in keypad mode (notice thee are commented out!) #"\␛OD": backward-char #"\␛OC": forward-char #"\␛OA": previous-history #"\␛OB": next-history ^q: quoted-insert $endif # An old-style binding. This happens to be the default. TAB: complete # Macros that are convenient for shell interaction $if Bash # edit the path "\^xp": "PATH=${PATH}\e\^e\^a\ef\^f" # prepare to type a quoted word -- # insert open and close double quotes # and move to just after the open quote "\^x\"": "\"\"\^b" # insert a backslash (testing backslash escapes in sequences and macros) "\^x\\": "\\" # Quote the current or previous word "\^xq": "\eb\"\ef\"" # Add a binding to refresh the line, which is unbound "\^xr": redraw-current-line # Edit variable on current line. "\␛\^v": "\^a\^k$\^y\␛\^e\^a\^y=" $endif # use a visible bell if one is available set bell-style visible # don't strip characters to 7 bits when reading set input-alt on # allow iso-latin1 characters to be inserted rather than converted to prefix-alt sequences set convert-alt off # display characters with the eighth bit set directly rather than as alt-prefixed characters set output-alt on # if there are more than 150 possible completions for a word, ask the user if he wants to see all of them set completion-query-items 150 # For FTP $if Ftp "\^xg": "get \␛?" "\^xt": "put \␛?" "\␛.": yank-last-arg $endif
Commands that may be bound to key sequences.
List your key bindings by executing
bind -P
or, for a more terse format, suitable for an
inputrc
file, bind -p
. (See Bash Builtins.)
Command names without an accompanying key sequence are unbound by default.
In the following descriptions, point
refers to the current cursor
position, and mark
refers to a cursor position saved by the set-mark
command.
The text between the point and mark is referred to as the region
.
beginning-of-line |
accept-line |
delete-char |
kill-line |
digit-argument |
complete |
start-kbd-macro |
re-read-init-file |
Readline library has a partial implementation of vi
commands, enough to allow simple editing.
It behaves as specified in the posix 1003.2 standard.
To switch between emacs
and vi
editing modes, use the set -o emacs
and set -o vi
commands (see The Set Builtin).
The Readline default is emacs
mode.
When entering vi
mode in "insertion" mode, ESC
switches to "command" mode, where you can edit the text of the line with the standard vi
movement keys, move to previous
history lines with k
and subsequent lines with j
, and
so forth.
Entering a tab
† invokes completion.
complete
specifies a comspec.
actions specified by the compspec are used. Only matches which are prefixed by the word being completed are returned.
When -f
or -d
is used for filename or
directory name completion, $FIGNORE
is used to filter the matches.
See Bash Variables.
Any completions specified by a filename expansion pattern to the -G
option are generated next.
The words generated by the pattern need not match the word being completed.
The $GLOBIGNORE
is not used to filter the matches, but $FIGNORE
is used.
-W
string is considered.
It is first split (using the characters in $IFS
as delimiters. Shell quoting is honored.)
Each word is then expanded using brace expansion, tilde expansion, parameter and variable expansion,
command substitution, and arithmetic expansion, as described above (see Shell Expansions).
The results are split (see Word Splitting). The results of the expansion are prefix-matched against the word being completed, and the matching words become the possible completions.
-F
and -C
are invoked.
When the command or function is invoked, $COMP_LINE
and $COMP_POINT
are assigned values as described above
(see Bash Variables).
If a shell function is being invoked, $COMP_WORDS
and $COMP_CWORD
are also set.
When the function or command is invoked, the first argument is the name of the command whose arguments are being completed, the
second argument is the word being completed, and the third argument is the word preceding the word being completed on the current command line.
No filtering of the generated completions against the word being completed
is performed; the function or command has complete freedom in generating the matches.
Any function specified with -F
is invoked first. It may use any of the shell facilities, including the
compgen
builtin described below
(see Programmable Completion Builtins), to generate the matches.
It must put the possible completions in the $COMPREPLY
array.
Next, any command specified with -C
is invoked in an environment equivalent to command substitution.
It should display a list of completions, one per line, to the standard output.
Backslash may be used to escape a newline.
After all of the possible completions are generated, any filter
specified with -X
is applied to the list.
The filter is a pattern as used for pathname expansion; a &
in the pattern is replaced with the text of the word being completed.
A literal &
may be escaped with a backslash; the backslash is removed before attempting a match.
Any completion that matches the pattern will be removed from the list.
A leading !
negates the pattern; in this case any completion not matching the pattern will be removed.
Finally, any prefix and suffix specified with -P
and -S
are added to each member of the completion list, and the result is
returned to the Readline completion code as the list of possible completions.
-o dirnames
was supplied to complete
when the compspec was defined, directory name completion is attempted.
-o plusdirs
was supplied to complete
when the compspec was defined, directory name completion is attempted and any matches are added to the results of the other actions.
By default, if a compspec is found, whatever it generates is returned to the completion code as the full set of possible completions.
The default Bash completions are not attempted, and the Readline default of filename completion is disabled.
If -o bashdefault
was supplied to complete
when the compspec was defined, the default Bash completions are attempted if the compspec generates no matches.
If -o default
was supplied to complete
when the
compspec was defined, Readline's default completion will be performed if the compspec (and, if attempted, the default Bash completions)
generate no matches.
When a compspec indicates that directory name completion is desired, the programmable completion functions force Readline to append a slash to completed names which are symbolic links to directories, subject to the value of the mark-directories Readline variable, regardless of the setting of the mark-symlinked-directories Readline variable.
Builtin commands to manipulate the programmable completion facilities:
compgen |