4a367ed324842af3db9370cb92dae81c48e3fc38
[platform/upstream/bash.git] / lib / readline / doc / rluser.texi
1 @comment %**start of header (This is for running Texinfo on a region.)
2 @setfilename rluser.info
3 @comment %**end of header (This is for running Texinfo on a region.)
4
5 @ignore
6 This file documents the end user interface to the GNU command line
7 editing features.  It is to be an appendix to manuals for programs which
8 use these features.  There is a document entitled "readline.texinfo"
9 which contains both end-user and programmer documentation for the
10 GNU Readline Library.
11
12 Copyright (C) 1988--2009 Free Software Foundation, Inc.
13
14 Authored by Brian Fox and Chet Ramey.
15
16 Permission is granted to process this file through Tex and print the
17 results, provided the printed document carries copying permission notice
18 identical to this one except for the removal of this paragraph (this
19 paragraph not being relevant to the printed manual).
20
21 Permission is granted to make and distribute verbatim copies of this manual
22 provided the copyright notice and this permission notice are preserved on
23 all copies.
24
25 Permission is granted to copy and distribute modified versions of this
26 manual under the conditions for verbatim copying, provided also that the
27 GNU Copyright statement is available to the distributee, and provided that
28 the entire resulting derived work is distributed under the terms of a
29 permission notice identical to this one.
30
31 Permission is granted to copy and distribute translations of this manual
32 into another language, under the above conditions for modified versions.
33 @end ignore
34
35 @comment If you are including this manual as an appendix, then set the
36 @comment variable readline-appendix.
37
38 @ifclear BashFeatures
39 @defcodeindex bt
40 @end ifclear
41
42 @node Command Line Editing
43 @chapter Command Line Editing
44
45 This chapter describes the basic features of the @sc{gnu}
46 command line editing interface.
47 @ifset BashFeatures
48 Command line editing is provided by the Readline library, which is
49 used by several different programs, including Bash.
50 Command line editing is enabled by default when using an interactive shell,
51 unless the @option{--noediting} option is supplied at shell invocation.
52 Line editing is also used when using the @option{-e} option to the
53 @code{read} builtin command (@pxref{Bash Builtins}).
54 By default, the line editing commands are similar to those of emacs.
55 A vi-style line editing interface is also available.
56 Line editing can be enabled at any time using the @option{-o emacs} or
57 @option{-o vi} options to the @code{set} builtin command
58 (@pxref{The Set Builtin}), or disabled using the @option{+o emacs} or 
59 @option{+o vi} options to @code{set}.
60 @end ifset
61
62 @menu
63 * Introduction and Notation::   Notation used in this text.
64 * Readline Interaction::        The minimum set of commands for editing a line.
65 * Readline Init File::          Customizing Readline from a user's view.
66 * Bindable Readline Commands::  A description of most of the Readline commands
67                                 available for binding
68 * Readline vi Mode::            A short description of how to make Readline
69                                 behave like the vi editor.
70 @ifset BashFeatures
71 * Programmable Completion::     How to specify the possible completions for
72                                 a specific command.
73 * Programmable Completion Builtins::    Builtin commands to specify how to
74                                 complete arguments for a particular command.
75 @end ifset
76 @end menu
77
78 @node Introduction and Notation
79 @section Introduction to Line Editing
80
81 The following paragraphs describe the notation used to represent
82 keystrokes.
83
84 The text @kbd{C-k} is read as `Control-K' and describes the character
85 produced when the @key{k} key is pressed while the Control key
86 is depressed.
87
88 The text @kbd{M-k} is read as `Meta-K' and describes the character
89 produced when the Meta key (if you have one) is depressed, and the @key{k}
90 key is pressed.
91 The Meta key is labeled @key{ALT} on many keyboards.
92 On keyboards with two keys labeled @key{ALT} (usually to either side of
93 the space bar), the @key{ALT} on the left side is generally set to
94 work as a Meta key.
95 The @key{ALT} key on the right may also be configured to work as a
96 Meta key or may be configured as some other modifier, such as a
97 Compose key for typing accented characters.
98
99 If you do not have a Meta or @key{ALT} key, or another key working as
100 a Meta key, the identical keystroke can be generated by typing @key{ESC}
101 @emph{first}, and then typing @key{k}.
102 Either process is known as @dfn{metafying} the @key{k} key.
103
104 The text @kbd{M-C-k} is read as `Meta-Control-k' and describes the
105 character produced by @dfn{metafying} @kbd{C-k}.
106
107 In addition, several keys have their own names.  Specifically,
108 @key{DEL}, @key{ESC}, @key{LFD}, @key{SPC}, @key{RET}, and @key{TAB} all
109 stand for themselves when seen in this text, or in an init file
110 (@pxref{Readline Init File}).
111 If your keyboard lacks a @key{LFD} key, typing @key{C-j} will
112 produce the desired character.
113 The @key{RET} key may be labeled @key{Return} or @key{Enter} on
114 some keyboards.
115
116 @node Readline Interaction
117 @section Readline Interaction
118 @cindex interaction, readline
119
120 Often during an interactive session you type in a long line of text,
121 only to notice that the first word on the line is misspelled.  The
122 Readline library gives you a set of commands for manipulating the text
123 as you type it in, allowing you to just fix your typo, and not forcing
124 you to retype the majority of the line.  Using these editing commands,
125 you move the cursor to the place that needs correction, and delete or
126 insert the text of the corrections.  Then, when you are satisfied with
127 the line, you simply press @key{RET}.  You do not have to be at the
128 end of the line to press @key{RET}; the entire line is accepted
129 regardless of the location of the cursor within the line.
130
131 @menu
132 * Readline Bare Essentials::    The least you need to know about Readline.
133 * Readline Movement Commands::  Moving about the input line.
134 * Readline Killing Commands::   How to delete text, and how to get it back!
135 * Readline Arguments::          Giving numeric arguments to commands.
136 * Searching::                   Searching through previous lines.
137 @end menu
138
139 @node Readline Bare Essentials
140 @subsection Readline Bare Essentials
141 @cindex notation, readline
142 @cindex command editing
143 @cindex editing command lines
144
145 In order to enter characters into the line, simply type them.  The typed
146 character appears where the cursor was, and then the cursor moves one
147 space to the right.  If you mistype a character, you can use your
148 erase character to back up and delete the mistyped character.
149
150 Sometimes you may mistype a character, and
151 not notice the error until you have typed several other characters.  In
152 that case, you can type @kbd{C-b} to move the cursor to the left, and then
153 correct your mistake.  Afterwards, you can move the cursor to the right
154 with @kbd{C-f}.
155
156 When you add text in the middle of a line, you will notice that characters
157 to the right of the cursor are `pushed over' to make room for the text
158 that you have inserted.  Likewise, when you delete text behind the cursor,
159 characters to the right of the cursor are `pulled back' to fill in the
160 blank space created by the removal of the text.  A list of the bare
161 essentials for editing the text of an input line follows.
162
163 @table @asis
164 @item @kbd{C-b}
165 Move back one character.
166 @item @kbd{C-f}
167 Move forward one character.
168 @item @key{DEL} or @key{Backspace}
169 Delete the character to the left of the cursor.
170 @item @kbd{C-d}
171 Delete the character underneath the cursor.
172 @item @w{Printing characters}
173 Insert the character into the line at the cursor.
174 @item @kbd{C-_} or @kbd{C-x C-u}
175 Undo the last editing command.  You can undo all the way back to an
176 empty line.
177 @end table
178
179 @noindent
180 (Depending on your configuration, the @key{Backspace} key be set to
181 delete the character to the left of the cursor and the @key{DEL} key set
182 to delete the character underneath the cursor, like @kbd{C-d}, rather
183 than the character to the left of the cursor.)
184
185 @node Readline Movement Commands
186 @subsection Readline Movement Commands
187
188
189 The above table describes the most basic keystrokes that you need
190 in order to do editing of the input line.  For your convenience, many
191 other commands have been added in addition to @kbd{C-b}, @kbd{C-f},
192 @kbd{C-d}, and @key{DEL}.  Here are some commands for moving more rapidly
193 about the line.
194
195 @table @kbd
196 @item C-a
197 Move to the start of the line.
198 @item C-e
199 Move to the end of the line.
200 @item M-f
201 Move forward a word, where a word is composed of letters and digits.
202 @item M-b
203 Move backward a word.
204 @item C-l
205 Clear the screen, reprinting the current line at the top.
206 @end table
207
208 Notice how @kbd{C-f} moves forward a character, while @kbd{M-f} moves
209 forward a word.  It is a loose convention that control keystrokes
210 operate on characters while meta keystrokes operate on words.
211
212 @node Readline Killing Commands
213 @subsection Readline Killing Commands
214
215 @cindex killing text
216 @cindex yanking text
217
218 @dfn{Killing} text means to delete the text from the line, but to save
219 it away for later use, usually by @dfn{yanking} (re-inserting)
220 it back into the line.
221 (`Cut' and `paste' are more recent jargon for `kill' and `yank'.)
222
223 If the description for a command says that it `kills' text, then you can
224 be sure that you can get the text back in a different (or the same)
225 place later.
226
227 When you use a kill command, the text is saved in a @dfn{kill-ring}.
228 Any number of consecutive kills save all of the killed text together, so
229 that when you yank it back, you get it all.  The kill
230 ring is not line specific; the text that you killed on a previously
231 typed line is available to be yanked back later, when you are typing
232 another line.
233 @cindex kill ring
234
235 Here is the list of commands for killing text.
236
237 @table @kbd
238 @item C-k
239 Kill the text from the current cursor position to the end of the line.
240
241 @item M-d
242 Kill from the cursor to the end of the current word, or, if between
243 words, to the end of the next word.
244 Word boundaries are the same as those used by @kbd{M-f}.
245
246 @item M-@key{DEL}
247 Kill from the cursor the start of the current word, or, if between
248 words, to the start of the previous word.
249 Word boundaries are the same as those used by @kbd{M-b}.
250
251 @item C-w
252 Kill from the cursor to the previous whitespace.  This is different than
253 @kbd{M-@key{DEL}} because the word boundaries differ.
254
255 @end table
256
257 Here is how to @dfn{yank} the text back into the line.  Yanking
258 means to copy the most-recently-killed text from the kill buffer.
259
260 @table @kbd
261 @item C-y
262 Yank the most recently killed text back into the buffer at the cursor.
263
264 @item M-y
265 Rotate the kill-ring, and yank the new top.  You can only do this if
266 the prior command is @kbd{C-y} or @kbd{M-y}.
267 @end table
268
269 @node Readline Arguments
270 @subsection Readline Arguments
271
272 You can pass numeric arguments to Readline commands.  Sometimes the
273 argument acts as a repeat count, other times it is the @i{sign} of the
274 argument that is significant.  If you pass a negative argument to a
275 command which normally acts in a forward direction, that command will
276 act in a backward direction.  For example, to kill text back to the
277 start of the line, you might type @samp{M-- C-k}.
278
279 The general way to pass numeric arguments to a command is to type meta
280 digits before the command.  If the first `digit' typed is a minus
281 sign (@samp{-}), then the sign of the argument will be negative.  Once
282 you have typed one meta digit to get the argument started, you can type
283 the remainder of the digits, and then the command.  For example, to give
284 the @kbd{C-d} command an argument of 10, you could type @samp{M-1 0 C-d},
285 which will delete the next ten characters on the input line.
286
287 @node Searching
288 @subsection Searching for Commands in the History
289
290 Readline provides commands for searching through the command history
291 @ifset BashFeatures
292 (@pxref{Bash History Facilities})
293 @end ifset
294 for lines containing a specified string.
295 There are two search modes:  @dfn{incremental} and @dfn{non-incremental}.
296
297 Incremental searches begin before the user has finished typing the
298 search string.
299 As each character of the search string is typed, Readline displays
300 the next entry from the history matching the string typed so far.
301 An incremental search requires only as many characters as needed to
302 find the desired history entry.
303 To search backward in the history for a particular string, type
304 @kbd{C-r}.  Typing @kbd{C-s} searches forward through the history.
305 The characters present in the value of the @code{isearch-terminators} variable
306 are used to terminate an incremental search.
307 If that variable has not been assigned a value, the @key{ESC} and
308 @kbd{C-J} characters will terminate an incremental search.
309 @kbd{C-g} will abort an incremental search and restore the original line.
310 When the search is terminated, the history entry containing the
311 search string becomes the current line.
312
313 To find other matching entries in the history list, type @kbd{C-r} or
314 @kbd{C-s} as appropriate.
315 This will search backward or forward in the history for the next
316 entry matching the search string typed so far.
317 Any other key sequence bound to a Readline command will terminate
318 the search and execute that command.
319 For instance, a @key{RET} will terminate the search and accept
320 the line, thereby executing the command from the history list.
321 A movement command will terminate the search, make the last line found
322 the current line, and begin editing.
323
324 Readline remembers the last incremental search string.  If two
325 @kbd{C-r}s are typed without any intervening characters defining a new
326 search string, any remembered search string is used.
327
328 Non-incremental searches read the entire search string before starting
329 to search for matching history lines.  The search string may be
330 typed by the user or be part of the contents of the current line.
331
332 @node Readline Init File
333 @section Readline Init File
334 @cindex initialization file, readline
335
336 Although the Readline library comes with a set of Emacs-like
337 keybindings installed by default, it is possible to use a different set
338 of keybindings.
339 Any user can customize programs that use Readline by putting
340 commands in an @dfn{inputrc} file, conventionally in his home directory.
341 The name of this
342 @ifset BashFeatures
343 file is taken from the value of the shell variable @env{INPUTRC}.  If
344 @end ifset
345 @ifclear BashFeatures
346 file is taken from the value of the environment variable @env{INPUTRC}.  If
347 @end ifclear
348 that variable is unset, the default is @file{~/.inputrc}.  If that
349 file does not exist or cannot be read, the ultimate default is
350 @file{/etc/inputrc}.
351
352 When a program which uses the Readline library starts up, the
353 init file is read, and the key bindings are set.
354
355 In addition, the @code{C-x C-r} command re-reads this init file, thus
356 incorporating any changes that you might have made to it.
357
358 @menu
359 * Readline Init File Syntax::   Syntax for the commands in the inputrc file.
360
361 * Conditional Init Constructs:: Conditional key bindings in the inputrc file.
362
363 * Sample Init File::            An example inputrc file.
364 @end menu
365
366 @node Readline Init File Syntax
367 @subsection Readline Init File Syntax
368
369 There are only a few basic constructs allowed in the
370 Readline init file.  Blank lines are ignored.
371 Lines beginning with a @samp{#} are comments.
372 Lines beginning with a @samp{$} indicate conditional
373 constructs (@pxref{Conditional Init Constructs}).  Other lines
374 denote variable settings and key bindings.
375
376 @table @asis
377 @item Variable Settings
378 You can modify the run-time behavior of Readline by
379 altering the values of variables in Readline
380 using the @code{set} command within the init file.
381 The syntax is simple:
382
383 @example
384 set @var{variable} @var{value}
385 @end example
386
387 @noindent
388 Here, for example, is how to
389 change from the default Emacs-like key binding to use
390 @code{vi} line editing commands:
391
392 @example
393 set editing-mode vi
394 @end example
395
396 Variable names and values, where appropriate, are recognized without regard
397 to case.  Unrecognized variable names are ignored.
398
399 Boolean variables (those that can be set to on or off) are set to on if
400 the value is null or empty, @var{on} (case-insensitive), or 1.  Any other
401 value results in the variable being set to off.
402
403 @ifset BashFeatures
404 The @w{@code{bind -V}} command lists the current Readline variable names
405 and values.  @xref{Bash Builtins}.
406 @end ifset
407
408 A great deal of run-time behavior is changeable with the following
409 variables.
410
411 @cindex variables, readline
412 @table @code
413
414 @item bell-style
415 @vindex bell-style
416 Controls what happens when Readline wants to ring the terminal bell.
417 If set to @samp{none}, Readline never rings the bell.  If set to
418 @samp{visible}, Readline uses a visible bell if one is available.
419 If set to @samp{audible} (the default), Readline attempts to ring
420 the terminal's bell.
421
422 @item bind-tty-special-chars
423 @vindex bind-tty-special-chars
424 If set to @samp{on}, Readline attempts to bind the control characters  
425 treated specially by the kernel's terminal driver to their Readline
426 equivalents.
427
428 @item comment-begin
429 @vindex comment-begin
430 The string to insert at the beginning of the line when the
431 @code{insert-comment} command is executed.  The default value
432 is @code{"#"}.
433
434 @item completion-ignore-case
435 If set to @samp{on}, Readline performs filename matching and completion
436 in a case-insensitive fashion.
437 The default value is @samp{off}.
438
439 @item completion-prefix-display-length
440 @vindex completion-prefix-display-length
441 The length in characters of the common prefix of a list of possible
442 completions that is displayed without modification.  When set to a
443 value greater than zero, common prefixes longer than this value are
444 replaced with an ellipsis when displaying possible completions.
445
446 @item completion-query-items
447 @vindex completion-query-items
448 The number of possible completions that determines when the user is
449 asked whether the list of possibilities should be displayed.
450 If the number of possible completions is greater than this value,
451 Readline will ask the user whether or not he wishes to view
452 them; otherwise, they are simply listed.
453 This variable must be set to an integer value greater than or equal to 0.
454 A negative value means Readline should never ask.
455 The default limit is @code{100}.
456
457 @item convert-meta
458 @vindex convert-meta
459 If set to @samp{on}, Readline will convert characters with the
460 eighth bit set to an @sc{ascii} key sequence by stripping the eighth
461 bit and prefixing an @key{ESC} character, converting them to a
462 meta-prefixed key sequence.  The default value is @samp{on}.
463
464 @item disable-completion
465 @vindex disable-completion
466 If set to @samp{On}, Readline will inhibit word completion.
467 Completion  characters will be inserted into the line as if they had
468 been mapped to @code{self-insert}.  The default is @samp{off}.
469
470 @item editing-mode
471 @vindex editing-mode
472 The @code{editing-mode} variable controls which default set of
473 key bindings is used.  By default, Readline starts up in Emacs editing
474 mode, where the keystrokes are most similar to Emacs.  This variable can be
475 set to either @samp{emacs} or @samp{vi}.
476
477 @item enable-keypad
478 @vindex enable-keypad
479 When set to @samp{on}, Readline will try to enable the application
480 keypad when it is called.  Some systems need this to enable the
481 arrow keys.  The default is @samp{off}.
482
483 @item expand-tilde
484 @vindex expand-tilde
485 If set to @samp{on}, tilde expansion is performed when Readline
486 attempts word completion.  The default is @samp{off}.
487
488 @item history-preserve-point
489 @vindex history-preserve-point
490 If set to @samp{on}, the history code attempts to place the point (the
491 current cursor position) at the
492 same location on each history line retrieved with @code{previous-history}
493 or @code{next-history}.  The default is @samp{off}.
494
495 @item history-size
496 @vindex history-size
497 Set the maximum number of history entries saved in the history list.  If
498 set to zero, the number of entries in the history list is not limited.
499
500 @item horizontal-scroll-mode
501 @vindex horizontal-scroll-mode
502 This variable can be set to either @samp{on} or @samp{off}.  Setting it
503 to @samp{on} means that the text of the lines being edited will scroll
504 horizontally on a single screen line when they are longer than the width
505 of the screen, instead of wrapping onto a new screen line.  By default,
506 this variable is set to @samp{off}.
507
508 @item input-meta
509 @vindex input-meta
510 @vindex meta-flag
511 If set to @samp{on}, Readline will enable eight-bit input (it
512 will not clear the eighth bit in the characters it reads),
513 regardless of what the terminal claims it can support.  The
514 default value is @samp{off}.  The name @code{meta-flag} is a
515 synonym for this variable.
516
517 @item isearch-terminators
518 @vindex isearch-terminators
519 The string of characters that should terminate an incremental search without
520 subsequently executing the character as a command (@pxref{Searching}).
521 If this variable has not been given a value, the characters @key{ESC} and
522 @kbd{C-J} will terminate an incremental search.
523
524 @item keymap
525 @vindex keymap
526 Sets Readline's idea of the current keymap for key binding commands.
527 Acceptable @code{keymap} names are
528 @code{emacs},
529 @code{emacs-standard},
530 @code{emacs-meta},
531 @code{emacs-ctlx},
532 @code{vi},
533 @code{vi-move},
534 @code{vi-command}, and
535 @code{vi-insert}.
536 @code{vi} is equivalent to @code{vi-command}; @code{emacs} is
537 equivalent to @code{emacs-standard}.  The default value is @code{emacs}.
538 The value of the @code{editing-mode} variable also affects the
539 default keymap.
540
541 @item mark-directories
542 If set to @samp{on}, completed directory names have a slash
543 appended.  The default is @samp{on}.
544
545 @item mark-modified-lines
546 @vindex mark-modified-lines
547 This variable, when set to @samp{on}, causes Readline to display an
548 asterisk (@samp{*}) at the start of history lines which have been modified.
549 This variable is @samp{off} by default.
550
551 @item mark-symlinked-directories
552 @vindex mark-symlinked-directories
553 If set to @samp{on}, completed names which are symbolic links
554 to directories have a slash appended (subject to the value of
555 @code{mark-directories}).
556 The default is @samp{off}.
557
558 @item match-hidden-files
559 @vindex match-hidden-files
560 This variable, when set to @samp{on}, causes Readline to match files whose
561 names begin with a @samp{.} (hidden files) when performing filename
562 completion, unless the leading @samp{.} is
563 supplied by the user in the filename to be completed.
564 This variable is @samp{on} by default.
565
566 @item output-meta
567 @vindex output-meta
568 If set to @samp{on}, Readline will display characters with the
569 eighth bit set directly rather than as a meta-prefixed escape
570 sequence.  The default is @samp{off}.
571
572 @item page-completions
573 @vindex page-completions
574 If set to @samp{on}, Readline uses an internal @code{more}-like pager
575 to display a screenful of possible completions at a time.
576 This variable is @samp{on} by default.
577
578 @item print-completions-horizontally
579 If set to @samp{on}, Readline will display completions with matches
580 sorted horizontally in alphabetical order, rather than down the screen.
581 The default is @samp{off}.
582
583 @item revert-all-at-newline
584 @vindex revert-all-at-newline
585 If set to @samp{on}, Readline will undo all changes to history lines
586 before returning when @code{accept-line} is executed.  By default,
587 history lines may be modified and retain individual undo lists across
588 calls to @code{readline}.  The default is @samp{off}.
589
590 @item show-all-if-ambiguous
591 @vindex show-all-if-ambiguous
592 This alters the default behavior of the completion functions.  If
593 set to @samp{on}, 
594 words which have more than one possible completion cause the
595 matches to be listed immediately instead of ringing the bell.
596 The default value is @samp{off}.
597
598 @item show-all-if-unmodified
599 @vindex show-all-if-unmodified
600 This alters the default behavior of the completion functions in
601 a fashion similar to @var{show-all-if-ambiguous}.
602 If set to @samp{on}, 
603 words which have more than one possible completion without any
604 possible partial completion (the possible completions don't share
605 a common prefix) cause the matches to be listed immediately instead
606 of ringing the bell.
607 The default value is @samp{off}.
608
609 @item visible-stats
610 @vindex visible-stats
611 If set to @samp{on}, a character denoting a file's type
612 is appended to the filename when listing possible
613 completions.  The default is @samp{off}.
614
615 @end table
616
617 @item Key Bindings
618 The syntax for controlling key bindings in the init file is
619 simple.  First you need to find the name of the command that you
620 want to change.  The following sections contain tables of the command
621 name, the default keybinding, if any, and a short description of what
622 the command does.
623
624 Once you know the name of the command, simply place on a line
625 in the init file the name of the key
626 you wish to bind the command to, a colon, and then the name of the
627 command.
628 There can be no space between the key name and the colon -- that will be
629 interpreted as part of the key name.
630 The name of the key can be expressed in different ways, depending on
631 what you find most comfortable.
632
633 In addition to command names, readline allows keys to be bound
634 to a string that is inserted when the key is pressed (a @var{macro}).
635
636 @ifset BashFeatures
637 The @w{@code{bind -p}} command displays Readline function names and
638 bindings in a format that can put directly into an initialization file.
639 @xref{Bash Builtins}.
640 @end ifset
641
642 @table @asis
643 @item @w{@var{keyname}: @var{function-name} or @var{macro}}
644 @var{keyname} is the name of a key spelled out in English.  For example:
645 @example
646 Control-u: universal-argument
647 Meta-Rubout: backward-kill-word
648 Control-o: "> output"
649 @end example
650
651 In the above example, @kbd{C-u} is bound to the function
652 @code{universal-argument},
653 @kbd{M-DEL} is bound to the function @code{backward-kill-word}, and
654 @kbd{C-o} is bound to run the macro
655 expressed on the right hand side (that is, to insert the text
656 @samp{> output} into the line).
657
658 A number of symbolic character names are recognized while
659 processing this key binding syntax:
660 @var{DEL},
661 @var{ESC},
662 @var{ESCAPE},
663 @var{LFD},
664 @var{NEWLINE},
665 @var{RET},
666 @var{RETURN},
667 @var{RUBOUT},
668 @var{SPACE},
669 @var{SPC},
670 and
671 @var{TAB}.
672
673 @item @w{"@var{keyseq}": @var{function-name} or @var{macro}}
674 @var{keyseq} differs from @var{keyname} above in that strings
675 denoting an entire key sequence can be specified, by placing
676 the key sequence in double quotes.  Some @sc{gnu} Emacs style key
677 escapes can be used, as in the following example, but the
678 special character names are not recognized.
679
680 @example
681 "\C-u": universal-argument
682 "\C-x\C-r": re-read-init-file
683 "\e[11~": "Function Key 1"
684 @end example
685
686 In the above example, @kbd{C-u} is again bound to the function
687 @code{universal-argument} (just as it was in the first example),
688 @samp{@kbd{C-x} @kbd{C-r}} is bound to the function @code{re-read-init-file},
689 and @samp{@key{ESC} @key{[} @key{1} @key{1} @key{~}} is bound to insert
690 the text @samp{Function Key 1}.
691
692 @end table
693
694 The following @sc{gnu} Emacs style escape sequences are available when
695 specifying key sequences:
696
697 @table @code
698 @item @kbd{\C-}
699 control prefix
700 @item @kbd{\M-}
701 meta prefix
702 @item @kbd{\e}
703 an escape character
704 @item @kbd{\\}
705 backslash
706 @item @kbd{\"}
707 @key{"}, a double quotation mark
708 @item @kbd{\'}
709 @key{'}, a single quote or apostrophe
710 @end table
711
712 In addition to the @sc{gnu} Emacs style escape sequences, a second
713 set of backslash escapes is available:
714
715 @table @code
716 @item \a
717 alert (bell)
718 @item \b
719 backspace
720 @item \d
721 delete
722 @item \f
723 form feed
724 @item \n
725 newline
726 @item \r
727 carriage return
728 @item \t
729 horizontal tab
730 @item \v
731 vertical tab
732 @item \@var{nnn}
733 the eight-bit character whose value is the octal value @var{nnn}
734 (one to three digits)
735 @item \x@var{HH}
736 the eight-bit character whose value is the hexadecimal value @var{HH}
737 (one or two hex digits)
738 @end table
739
740 When entering the text of a macro, single or double quotes must
741 be used to indicate a macro definition.
742 Unquoted text is assumed to be a function name.
743 In the macro body, the backslash escapes described above are expanded.
744 Backslash will quote any other character in the macro text,
745 including @samp{"} and @samp{'}.
746 For example, the following binding will make @samp{@kbd{C-x} \}
747 insert a single @samp{\} into the line:
748 @example
749 "\C-x\\": "\\"
750 @end example
751
752 @end table
753
754 @node Conditional Init Constructs
755 @subsection Conditional Init Constructs
756
757 Readline implements a facility similar in spirit to the conditional
758 compilation features of the C preprocessor which allows key
759 bindings and variable settings to be performed as the result
760 of tests.  There are four parser directives used.
761
762 @table @code
763 @item $if
764 The @code{$if} construct allows bindings to be made based on the
765 editing mode, the terminal being used, or the application using
766 Readline.  The text of the test extends to the end of the line;
767 no characters are required to isolate it.
768
769 @table @code
770 @item mode
771 The @code{mode=} form of the @code{$if} directive is used to test
772 whether Readline is in @code{emacs} or @code{vi} mode.
773 This may be used in conjunction
774 with the @samp{set keymap} command, for instance, to set bindings in
775 the @code{emacs-standard} and @code{emacs-ctlx} keymaps only if
776 Readline is starting out in @code{emacs} mode.
777
778 @item term
779 The @code{term=} form may be used to include terminal-specific
780 key bindings, perhaps to bind the key sequences output by the
781 terminal's function keys.  The word on the right side of the
782 @samp{=} is tested against both the full name of the terminal and
783 the portion of the terminal name before the first @samp{-}.  This
784 allows @code{sun} to match both @code{sun} and @code{sun-cmd},
785 for instance.
786
787 @item application
788 The @var{application} construct is used to include
789 application-specific settings.  Each program using the Readline
790 library sets the @var{application name}, and you can test for
791 a particular value. 
792 This could be used to bind key sequences to functions useful for
793 a specific program.  For instance, the following command adds a
794 key sequence that quotes the current or previous word in Bash:
795 @example
796 $if Bash
797 # Quote the current or previous word
798 "\C-xq": "\eb\"\ef\""
799 $endif
800 @end example
801 @end table
802
803 @item $endif
804 This command, as seen in the previous example, terminates an
805 @code{$if} command.
806
807 @item $else
808 Commands in this branch of the @code{$if} directive are executed if
809 the test fails.
810
811 @item $include
812 This directive takes a single filename as an argument and reads commands
813 and bindings from that file.
814 For example, the following directive reads from @file{/etc/inputrc}:
815 @example
816 $include /etc/inputrc
817 @end example
818 @end table
819
820 @node Sample Init File
821 @subsection Sample Init File
822
823 Here is an example of an @var{inputrc} file.  This illustrates key
824 binding, variable assignment, and conditional syntax.
825
826 @example
827 @page
828 # This file controls the behaviour of line input editing for
829 # programs that use the GNU Readline library.  Existing
830 # programs include FTP, Bash, and GDB.
831 #
832 # You can re-read the inputrc file with C-x C-r.
833 # Lines beginning with '#' are comments.
834 #
835 # First, include any systemwide bindings and variable
836 # assignments from /etc/Inputrc
837 $include /etc/Inputrc
838
839 #
840 # Set various bindings for emacs mode.
841
842 set editing-mode emacs 
843
844 $if mode=emacs
845
846 Meta-Control-h: backward-kill-word      Text after the function name is ignored
847
848 #
849 # Arrow keys in keypad mode
850 #
851 #"\M-OD":        backward-char
852 #"\M-OC":        forward-char
853 #"\M-OA":        previous-history
854 #"\M-OB":        next-history
855 #
856 # Arrow keys in ANSI mode
857 #
858 "\M-[D":        backward-char
859 "\M-[C":        forward-char
860 "\M-[A":        previous-history
861 "\M-[B":        next-history
862 #
863 # Arrow keys in 8 bit keypad mode
864 #
865 #"\M-\C-OD":       backward-char
866 #"\M-\C-OC":       forward-char
867 #"\M-\C-OA":       previous-history
868 #"\M-\C-OB":       next-history
869 #
870 # Arrow keys in 8 bit ANSI mode
871 #
872 #"\M-\C-[D":       backward-char
873 #"\M-\C-[C":       forward-char
874 #"\M-\C-[A":       previous-history
875 #"\M-\C-[B":       next-history
876
877 C-q: quoted-insert
878
879 $endif
880
881 # An old-style binding.  This happens to be the default.
882 TAB: complete
883
884 # Macros that are convenient for shell interaction
885 $if Bash
886 # edit the path
887 "\C-xp": "PATH=$@{PATH@}\e\C-e\C-a\ef\C-f"
888 # prepare to type a quoted word --
889 # insert open and close double quotes
890 # and move to just after the open quote
891 "\C-x\"": "\"\"\C-b"
892 # insert a backslash (testing backslash escapes
893 # in sequences and macros)
894 "\C-x\\": "\\"
895 # Quote the current or previous word
896 "\C-xq": "\eb\"\ef\""
897 # Add a binding to refresh the line, which is unbound
898 "\C-xr": redraw-current-line
899 # Edit variable on current line.
900 "\M-\C-v": "\C-a\C-k$\C-y\M-\C-e\C-a\C-y="
901 $endif
902
903 # use a visible bell if one is available
904 set bell-style visible
905
906 # don't strip characters to 7 bits when reading
907 set input-meta on
908
909 # allow iso-latin1 characters to be inserted rather
910 # than converted to prefix-meta sequences
911 set convert-meta off
912
913 # display characters with the eighth bit set directly
914 # rather than as meta-prefixed characters
915 set output-meta on
916
917 # if there are more than 150 possible completions for
918 # a word, ask the user if he wants to see all of them
919 set completion-query-items 150
920
921 # For FTP
922 $if Ftp
923 "\C-xg": "get \M-?"
924 "\C-xt": "put \M-?"
925 "\M-.": yank-last-arg
926 $endif
927 @end example
928
929 @node Bindable Readline Commands
930 @section Bindable Readline Commands
931
932 @menu
933 * Commands For Moving::         Moving about the line.
934 * Commands For History::        Getting at previous lines.
935 * Commands For Text::           Commands for changing text.
936 * Commands For Killing::        Commands for killing and yanking.
937 * Numeric Arguments::           Specifying numeric arguments, repeat counts.
938 * Commands For Completion::     Getting Readline to do the typing for you.
939 * Keyboard Macros::             Saving and re-executing typed characters
940 * Miscellaneous Commands::      Other miscellaneous commands.
941 @end menu
942
943 This section describes Readline commands that may be bound to key
944 sequences.
945 @ifset BashFeatures
946 You can list your key bindings by executing
947 @w{@code{bind -P}} or, for a more terse format, suitable for an
948 @var{inputrc} file, @w{@code{bind -p}}.  (@xref{Bash Builtins}.)
949 @end ifset
950 Command names without an accompanying key sequence are unbound by default.
951
952 In the following descriptions, @dfn{point} refers to the current cursor
953 position, and @dfn{mark} refers to a cursor position saved by the
954 @code{set-mark} command.
955 The text between the point and mark is referred to as the @dfn{region}.
956
957 @node Commands For Moving
958 @subsection Commands For Moving
959 @ftable @code
960 @item beginning-of-line (C-a)
961 Move to the start of the current line.
962
963 @item end-of-line (C-e)
964 Move to the end of the line.
965
966 @item forward-char (C-f)
967 Move forward a character.
968
969 @item backward-char (C-b)
970 Move back a character.
971
972 @item forward-word (M-f)
973 Move forward to the end of the next word.
974 Words are composed of letters and digits.
975
976 @item backward-word (M-b)
977 Move back to the start of the current or previous word.
978 Words are composed of letters and digits.
979
980 @ifset BashFeatures
981 @item shell-forward-word ()
982 Move forward to the end of the next word.
983 Words are delimited by non-quoted shell metacharacters.
984
985 @item shell-backward-word ()
986 Move back to the start of the current or previous word.
987 Words are delimited by non-quoted shell metacharacters.
988 @end ifset
989
990 @item clear-screen (C-l)
991 Clear the screen and redraw the current line,
992 leaving the current line at the top of the screen.
993
994 @item redraw-current-line ()
995 Refresh the current line.  By default, this is unbound.
996
997 @end ftable
998
999 @node Commands For History
1000 @subsection Commands For Manipulating The History
1001
1002 @ftable @code
1003 @item accept-line (Newline or Return)
1004 @ifset BashFeatures
1005 Accept the line regardless of where the cursor is.
1006 If this line is
1007 non-empty, add it to the history list according to the setting of
1008 the @env{HISTCONTROL} and @env{HISTIGNORE} variables.
1009 If this line is a modified history line, then restore the history line
1010 to its original state.
1011 @end ifset
1012 @ifclear BashFeatures
1013 Accept the line regardless of where the cursor is.
1014 If this line is
1015 non-empty, it may be added to the history list for future recall with
1016 @code{add_history()}.
1017 If this line is a modified history line, the history line is restored
1018 to its original state.
1019 @end ifclear
1020
1021 @item previous-history (C-p)
1022 Move `back' through the history list, fetching the previous command.
1023
1024 @item next-history (C-n)
1025 Move `forward' through the history list, fetching the next command.
1026
1027 @item beginning-of-history (M-<)
1028 Move to the first line in the history.
1029
1030 @item end-of-history (M->)
1031 Move to the end of the input history, i.e., the line currently
1032 being entered.
1033
1034 @item reverse-search-history (C-r)
1035 Search backward starting at the current line and moving `up' through
1036 the history as necessary.  This is an incremental search.
1037
1038 @item forward-search-history (C-s)
1039 Search forward starting at the current line and moving `down' through
1040 the the history as necessary.  This is an incremental search.
1041
1042 @item non-incremental-reverse-search-history (M-p)
1043 Search backward starting at the current line and moving `up'
1044 through the history as necessary using a non-incremental search
1045 for a string supplied by the user.
1046
1047 @item non-incremental-forward-search-history (M-n)
1048 Search forward starting at the current line and moving `down'
1049 through the the history as necessary using a non-incremental search
1050 for a string supplied by the user.
1051
1052 @item history-search-forward ()
1053 Search forward through the history for the string of characters
1054 between the start of the current line and the point.
1055 This is a non-incremental search.
1056 By default, this command is unbound.
1057
1058 @item history-search-backward ()
1059 Search backward through the history for the string of characters
1060 between the start of the current line and the point.  This
1061 is a non-incremental search.  By default, this command is unbound.
1062
1063 @item yank-nth-arg (M-C-y)
1064 Insert the first argument to the previous command (usually
1065 the second word on the previous line) at point.
1066 With an argument @var{n},
1067 insert the @var{n}th word from the previous command (the words
1068 in the previous command begin with word 0).  A negative argument
1069 inserts the @var{n}th word from the end of the previous command.
1070 Once the argument @var{n} is computed, the argument is extracted
1071 as if the @samp{!@var{n}} history expansion had been specified.
1072
1073 @item yank-last-arg (M-. or M-_)
1074 Insert last argument to the previous command (the last word of the
1075 previous history entry).  With an
1076 argument, behave exactly like @code{yank-nth-arg}.
1077 Successive calls to @code{yank-last-arg} move back through the history
1078 list, inserting the last argument of each line in turn.
1079 The history expansion facilities are used to extract the last argument,
1080 as if the @samp{!$} history expansion had been specified.
1081
1082 @end ftable
1083
1084 @node Commands For Text
1085 @subsection Commands For Changing Text
1086
1087 @ftable @code
1088 @item delete-char (C-d)
1089 Delete the character at point.  If point is at the
1090 beginning of the line, there are no characters in the line, and
1091 the last character typed was not bound to @code{delete-char}, then
1092 return @sc{eof}.
1093
1094 @item backward-delete-char (Rubout)
1095 Delete the character behind the cursor.  A numeric argument means
1096 to kill the characters instead of deleting them.
1097
1098 @item forward-backward-delete-char ()
1099 Delete the character under the cursor, unless the cursor is at the
1100 end of the line, in which case the character behind the cursor is
1101 deleted.  By default, this is not bound to a key.
1102
1103 @item quoted-insert (C-q or C-v)
1104 Add the next character typed to the line verbatim.  This is
1105 how to insert key sequences like @kbd{C-q}, for example.
1106
1107 @ifclear BashFeatures
1108 @item tab-insert (M-@key{TAB})
1109 Insert a tab character.
1110 @end ifclear
1111
1112 @item self-insert (a, b, A, 1, !, @dots{})
1113 Insert yourself.
1114
1115 @item transpose-chars (C-t)
1116 Drag the character before the cursor forward over
1117 the character at the cursor, moving the
1118 cursor forward as well.  If the insertion point
1119 is at the end of the line, then this
1120 transposes the last two characters of the line.
1121 Negative arguments have no effect.
1122
1123 @item transpose-words (M-t)
1124 Drag the word before point past the word after point,
1125 moving point past that word as well.
1126 If the insertion point is at the end of the line, this transposes
1127 the last two words on the line.
1128
1129 @item upcase-word (M-u)
1130 Uppercase the current (or following) word.  With a negative argument,
1131 uppercase the previous word, but do not move the cursor.
1132
1133 @item downcase-word (M-l)
1134 Lowercase the current (or following) word.  With a negative argument,
1135 lowercase the previous word, but do not move the cursor.
1136
1137 @item capitalize-word (M-c)
1138 Capitalize the current (or following) word.  With a negative argument,
1139 capitalize the previous word, but do not move the cursor.
1140
1141 @item overwrite-mode ()
1142 Toggle overwrite mode.  With an explicit positive numeric argument,
1143 switches to overwrite mode.  With an explicit non-positive numeric
1144 argument, switches to insert mode.  This command affects only
1145 @code{emacs} mode; @code{vi} mode does overwrite differently.
1146 Each call to @code{readline()} starts in insert mode.
1147
1148 In overwrite mode, characters bound to @code{self-insert} replace
1149 the text at point rather than pushing the text to the right.
1150 Characters bound to @code{backward-delete-char} replace the character
1151 before point with a space.
1152
1153 By default, this command is unbound.
1154
1155 @end ftable
1156
1157 @node Commands For Killing
1158 @subsection Killing And Yanking
1159
1160 @ftable @code
1161
1162 @item kill-line (C-k)
1163 Kill the text from point to the end of the line.
1164
1165 @item backward-kill-line (C-x Rubout)
1166 Kill backward to the beginning of the line.
1167
1168 @item unix-line-discard (C-u)
1169 Kill backward from the cursor to the beginning of the current line.
1170
1171 @item kill-whole-line ()
1172 Kill all characters on the current line, no matter where point is.
1173 By default, this is unbound.
1174
1175 @item kill-word (M-d)
1176 Kill from point to the end of the current word, or if between
1177 words, to the end of the next word.
1178 Word boundaries are the same as @code{forward-word}.
1179
1180 @item backward-kill-word (M-@key{DEL})
1181 Kill the word behind point.
1182 Word boundaries are the same as @code{backward-word}.
1183
1184 @ifset BashFeatures
1185 @item shell-kill-word ()
1186 Kill from point to the end of the current word, or if between
1187 words, to the end of the next word.
1188 Word boundaries are the same as @code{shell-forward-word}.
1189
1190 @item backward-kill-word ()
1191 Kill the word behind point.
1192 Word boundaries are the same as @code{shell-backward-word}.
1193 @end ifset
1194
1195 @item unix-word-rubout (C-w)
1196 Kill the word behind point, using white space as a word boundary.
1197 The killed text is saved on the kill-ring.
1198
1199 @item unix-filename-rubout ()
1200 Kill the word behind point, using white space and the slash character
1201 as the word boundaries.
1202 The killed text is saved on the kill-ring.
1203
1204 @item delete-horizontal-space ()
1205 Delete all spaces and tabs around point.  By default, this is unbound.
1206
1207 @item kill-region ()
1208 Kill the text in the current region.
1209 By default, this command is unbound.
1210
1211 @item copy-region-as-kill ()
1212 Copy the text in the region to the kill buffer, so it can be yanked
1213 right away.  By default, this command is unbound.
1214
1215 @item copy-backward-word ()
1216 Copy the word before point to the kill buffer.
1217 The word boundaries are the same as @code{backward-word}.
1218 By default, this command is unbound.
1219
1220 @item copy-forward-word ()
1221 Copy the word following point to the kill buffer.
1222 The word boundaries are the same as @code{forward-word}.
1223 By default, this command is unbound.
1224
1225 @item yank (C-y)
1226 Yank the top of the kill ring into the buffer at point.
1227
1228 @item yank-pop (M-y)
1229 Rotate the kill-ring, and yank the new top.  You can only do this if
1230 the prior command is @code{yank} or @code{yank-pop}.
1231 @end ftable
1232
1233 @node Numeric Arguments
1234 @subsection Specifying Numeric Arguments
1235 @ftable @code
1236
1237 @item digit-argument (@kbd{M-0}, @kbd{M-1}, @dots{} @kbd{M--})
1238 Add this digit to the argument already accumulating, or start a new
1239 argument.  @kbd{M--} starts a negative argument.
1240
1241 @item universal-argument ()
1242 This is another way to specify an argument.
1243 If this command is followed by one or more digits, optionally with a
1244 leading minus sign, those digits define the argument.
1245 If the command is followed by digits, executing @code{universal-argument}
1246 again ends the numeric argument, but is otherwise ignored.
1247 As a special case, if this command is immediately followed by a
1248 character that is neither a digit or minus sign, the argument count
1249 for the next command is multiplied by four.
1250 The argument count is initially one, so executing this function the
1251 first time makes the argument count four, a second time makes the
1252 argument count sixteen, and so on.
1253 By default, this is not bound to a key.
1254 @end ftable
1255
1256 @node Commands For Completion
1257 @subsection Letting Readline Type For You
1258
1259 @ftable @code
1260 @item complete (@key{TAB})
1261 Attempt to perform completion on the text before point.
1262 The actual completion performed is application-specific.
1263 @ifset BashFeatures
1264 Bash attempts completion treating the text as a variable (if the
1265 text begins with @samp{$}), username (if the text begins with
1266 @samp{~}), hostname (if the text begins with @samp{@@}), or
1267 command (including aliases and functions) in turn.  If none 
1268 of these produces a match, filename completion is attempted.
1269 @end ifset
1270 @ifclear BashFeatures
1271 The default is filename completion.
1272 @end ifclear
1273
1274 @item possible-completions (M-?)
1275 List the possible completions of the text before point.
1276
1277 @item insert-completions (M-*)
1278 Insert all completions of the text before point that would have
1279 been generated by @code{possible-completions}.
1280
1281 @item menu-complete ()
1282 Similar to @code{complete}, but replaces the word to be completed
1283 with a single match from the list of possible completions.
1284 Repeated execution of @code{menu-complete} steps through the list
1285 of possible completions, inserting each match in turn.
1286 At the end of the list of completions, the bell is rung
1287 (subject to the setting of @code{bell-style})
1288 and the original text is restored.
1289 An argument of @var{n} moves @var{n} positions forward in the list
1290 of matches; a negative argument may be used to move backward
1291 through the list.
1292 This command is intended to be bound to @key{TAB}, but is unbound
1293 by default.
1294
1295 @item delete-char-or-list ()
1296 Deletes the character under the cursor if not at the beginning or
1297 end of the line (like @code{delete-char}).
1298 If at the end of the line, behaves identically to
1299 @code{possible-completions}.
1300 This command is unbound by default.
1301
1302 @ifset BashFeatures
1303 @item complete-filename (M-/)
1304 Attempt filename completion on the text before point.
1305
1306 @item possible-filename-completions (C-x /)
1307 List the possible completions of the text before point,
1308 treating it as a filename.
1309
1310 @item complete-username (M-~)
1311 Attempt completion on the text before point, treating
1312 it as a username.
1313
1314 @item possible-username-completions (C-x ~)
1315 List the possible completions of the text before point,
1316 treating it as a username.
1317
1318 @item complete-variable (M-$)
1319 Attempt completion on the text before point, treating
1320 it as a shell variable.
1321
1322 @item possible-variable-completions (C-x $)
1323 List the possible completions of the text before point,
1324 treating it as a shell variable.
1325
1326 @item complete-hostname (M-@@)
1327 Attempt completion on the text before point, treating
1328 it as a hostname.
1329
1330 @item possible-hostname-completions (C-x @@)
1331 List the possible completions of the text before point,
1332 treating it as a hostname.
1333
1334 @item complete-command (M-!)
1335 Attempt completion on the text before point, treating
1336 it as a command name.  Command completion attempts to
1337 match the text against aliases, reserved words, shell
1338 functions, shell builtins, and finally executable filenames,
1339 in that order.
1340
1341 @item possible-command-completions (C-x !)
1342 List the possible completions of the text before point,
1343 treating it as a command name.
1344
1345 @item dynamic-complete-history (M-@key{TAB})
1346 Attempt completion on the text before point, comparing
1347 the text against lines from the history list for possible
1348 completion matches.
1349
1350 @item dabbrev-expand ()
1351 Attempt menu completion on the text before point, comparing
1352 the text against lines from the history list for possible
1353 completion matches.
1354
1355 @item complete-into-braces (M-@{)
1356 Perform filename completion and insert the list of possible completions
1357 enclosed within braces so the list is available to the shell
1358 (@pxref{Brace Expansion}).
1359
1360 @end ifset
1361 @end ftable
1362
1363 @node Keyboard Macros
1364 @subsection Keyboard Macros
1365 @ftable @code
1366
1367 @item start-kbd-macro (C-x ()
1368 Begin saving the characters typed into the current keyboard macro.
1369
1370 @item end-kbd-macro (C-x ))
1371 Stop saving the characters typed into the current keyboard macro
1372 and save the definition.
1373
1374 @item call-last-kbd-macro (C-x e)
1375 Re-execute the last keyboard macro defined, by making the characters
1376 in the macro appear as if typed at the keyboard.
1377
1378 @end ftable
1379
1380 @node Miscellaneous Commands
1381 @subsection Some Miscellaneous Commands
1382 @ftable @code
1383
1384 @item re-read-init-file (C-x C-r)
1385 Read in the contents of the @var{inputrc} file, and incorporate
1386 any bindings or variable assignments found there.
1387
1388 @item abort (C-g)
1389 Abort the current editing command and
1390 ring the terminal's bell (subject to the setting of
1391 @code{bell-style}).
1392
1393 @item do-uppercase-version (M-a, M-b, M-@var{x}, @dots{})
1394 If the metafied character @var{x} is lowercase, run the command
1395 that is bound to the corresponding uppercase character.
1396
1397 @item prefix-meta (@key{ESC})
1398 Metafy the next character typed.  This is for keyboards
1399 without a meta key.  Typing @samp{@key{ESC} f} is equivalent to typing
1400 @kbd{M-f}.
1401
1402 @item undo (C-_ or C-x C-u)
1403 Incremental undo, separately remembered for each line.
1404
1405 @item revert-line (M-r)
1406 Undo all changes made to this line.  This is like executing the @code{undo}
1407 command enough times to get back to the beginning.
1408
1409 @ifset BashFeatures
1410 @item tilde-expand (M-&)
1411 @end ifset
1412 @ifclear BashFeatures
1413 @item tilde-expand (M-~)
1414 @end ifclear
1415 Perform tilde expansion on the current word.
1416
1417 @item set-mark (C-@@)
1418 Set the mark to the point.  If a
1419 numeric argument is supplied, the mark is set to that position.
1420
1421 @item exchange-point-and-mark (C-x C-x)
1422 Swap the point with the mark.  The current cursor position is set to
1423 the saved position, and the old cursor position is saved as the mark.
1424
1425 @item character-search (C-])
1426 A character is read and point is moved to the next occurrence of that
1427 character.  A negative count searches for previous occurrences.
1428
1429 @item character-search-backward (M-C-])
1430 A character is read and point is moved to the previous occurrence
1431 of that character.  A negative count searches for subsequent
1432 occurrences.
1433
1434 @item insert-comment (M-#)
1435 Without a numeric argument, the value of the @code{comment-begin}
1436 variable is inserted at the beginning of the current line.
1437 If a numeric argument is supplied, this command acts as a toggle:  if
1438 the characters at the beginning of the line do not match the value
1439 of @code{comment-begin}, the value is inserted, otherwise
1440 the characters in @code{comment-begin} are deleted from the beginning of
1441 the line.
1442 In either case, the line is accepted as if a newline had been typed.
1443 @ifset BashFeatures
1444 The default value of @code{comment-begin} causes this command
1445 to make the current line a shell comment.
1446 If a numeric argument causes the comment character to be removed, the line
1447 will be executed by the shell.
1448 @end ifset
1449
1450 @item dump-functions ()
1451 Print all of the functions and their key bindings to the
1452 Readline output stream.  If a numeric argument is supplied,
1453 the output is formatted in such a way that it can be made part
1454 of an @var{inputrc} file.  This command is unbound by default.
1455
1456 @item dump-variables ()
1457 Print all of the settable variables and their values to the
1458 Readline output stream.  If a numeric argument is supplied,
1459 the output is formatted in such a way that it can be made part
1460 of an @var{inputrc} file.  This command is unbound by default.
1461
1462 @item dump-macros ()
1463 Print all of the Readline key sequences bound to macros and the
1464 strings they output.  If a numeric argument is supplied,
1465 the output is formatted in such a way that it can be made part
1466 of an @var{inputrc} file.  This command is unbound by default.
1467
1468 @ifset BashFeatures
1469 @item glob-complete-word (M-g)
1470 The word before point is treated as a pattern for pathname expansion,
1471 with an asterisk implicitly appended.  This pattern is used to
1472 generate a list of matching file names for possible completions.
1473
1474 @item glob-expand-word (C-x *)
1475 The word before point is treated as a pattern for pathname expansion,
1476 and the list of matching file names is inserted, replacing the word.
1477 If a numeric argument is supplied, a @samp{*} is appended before
1478 pathname expansion.
1479
1480 @item glob-list-expansions (C-x g)
1481 The list of expansions that would have been generated by
1482 @code{glob-expand-word} is displayed, and the line is redrawn.
1483 If a numeric argument is supplied, a @samp{*} is appended before
1484 pathname expansion.
1485
1486 @item display-shell-version (C-x C-v)
1487 Display version information about the current instance of Bash.
1488
1489 @item shell-expand-line (M-C-e)
1490 Expand the line as the shell does.
1491 This performs alias and history expansion as well as all of the shell
1492 word expansions (@pxref{Shell Expansions}).
1493
1494 @item history-expand-line (M-^)
1495 Perform history expansion on the current line.
1496
1497 @item magic-space ()
1498 Perform history expansion on the current line and insert a space
1499 (@pxref{History Interaction}).
1500
1501 @item alias-expand-line ()
1502 Perform alias expansion on the current line (@pxref{Aliases}).
1503
1504 @item history-and-alias-expand-line ()
1505 Perform history and alias expansion on the current line.
1506
1507 @item insert-last-argument (M-. or M-_)
1508 A synonym for @code{yank-last-arg}.
1509
1510 @item operate-and-get-next (C-o)
1511 Accept the current line for execution and fetch the next line
1512 relative to the current line from the history for editing.  Any
1513 argument is ignored.
1514
1515 @item edit-and-execute-command (C-xC-e)
1516 Invoke an editor on the current command line, and execute the result as shell
1517 commands.
1518 Bash attempts to invoke
1519 @code{$VISUAL}, @code{$EDITOR}, and @code{emacs}
1520 as the editor, in that order.
1521
1522 @end ifset
1523
1524 @ifclear BashFeatures
1525 @item emacs-editing-mode (C-e)
1526 When in @code{vi} command mode, this causes a switch to @code{emacs}
1527 editing mode.
1528
1529 @item vi-editing-mode (M-C-j)
1530 When in @code{emacs} editing mode, this causes a switch to @code{vi}
1531 editing mode.
1532
1533 @end ifclear
1534
1535 @end ftable
1536
1537 @node Readline vi Mode
1538 @section Readline vi Mode
1539
1540 While the Readline library does not have a full set of @code{vi}
1541 editing functions, it does contain enough to allow simple editing
1542 of the line.  The Readline @code{vi} mode behaves as specified in
1543 the @sc{posix} 1003.2 standard.
1544
1545 @ifset BashFeatures
1546 In order to switch interactively between @code{emacs} and @code{vi}
1547 editing modes, use the @samp{set -o emacs} and @samp{set -o vi}
1548 commands (@pxref{The Set Builtin}).
1549 @end ifset
1550 @ifclear BashFeatures
1551 In order to switch interactively between @code{emacs} and @code{vi}
1552 editing modes, use the command @kbd{M-C-j} (bound to emacs-editing-mode
1553 when in @code{vi} mode and to vi-editing-mode in @code{emacs} mode).
1554 @end ifclear
1555 The Readline default is @code{emacs} mode.
1556
1557 When you enter a line in @code{vi} mode, you are already placed in
1558 `insertion' mode, as if you had typed an @samp{i}.  Pressing @key{ESC}
1559 switches you into `command' mode, where you can edit the text of the
1560 line with the standard @code{vi} movement keys, move to previous
1561 history lines with @samp{k} and subsequent lines with @samp{j}, and
1562 so forth.
1563
1564 @ifset BashFeatures
1565 @node Programmable Completion
1566 @section Programmable Completion
1567 @cindex programmable completion
1568
1569 When word completion is attempted for an argument to a command for
1570 which a completion specification (a @var{compspec}) has been defined
1571 using the @code{complete} builtin (@pxref{Programmable Completion Builtins}),
1572 the programmable completion facilities are invoked. 
1573
1574 First, the command name is identified.
1575 If a compspec has been defined for that command, the
1576 compspec is used to generate the list of possible completions for the word.
1577 If the command word is a full pathname, a compspec for the full
1578 pathname is searched for first.
1579 If no compspec is found for the full pathname, an attempt is made to
1580 find a compspec for the portion following the final slash.
1581
1582 Once a compspec has been found, it is used to generate the list of
1583 matching words.
1584 If a compspec is not found, the default Bash completion
1585 described above (@pxref{Commands For Completion}) is performed.
1586
1587 First, the actions specified by the compspec are used.
1588 Only matches which are prefixed by the word being completed are
1589 returned.
1590 When the @option{-f} or @option{-d} option is used for filename or
1591 directory name completion, the shell variable @env{FIGNORE} is
1592 used to filter the matches.
1593 @xref{Bash Variables}, for a description of @env{FIGNORE}.
1594
1595 Any completions specified by a filename expansion pattern to the
1596 @option{-G} option are generated next.
1597 The words generated by the pattern need not match the word being completed.
1598 The @env{GLOBIGNORE} shell variable is not used to filter the matches,
1599 but the @env{FIGNORE} shell variable is used.
1600
1601 Next, the string specified as the argument to the @option{-W} option
1602 is considered.
1603 The string is first split using the characters in the @env{IFS}
1604 special variable as delimiters.
1605 Shell quoting is honored.
1606 Each word is then expanded using
1607 brace expansion, tilde expansion, parameter and variable expansion,
1608 command substitution, and arithmetic expansion,
1609 as described above (@pxref{Shell Expansions}).
1610 The results are split using the rules described above
1611 (@pxref{Word Splitting}).
1612 The results of the expansion are prefix-matched against the word being
1613 completed, and the matching words become the possible completions.
1614
1615 After these matches have been generated, any shell function or command
1616 specified with the @option{-F} and @option{-C} options is invoked.
1617 When the command or function is invoked, the @env{COMP_LINE},
1618 @env{COMP_POINT}, @env{COMP_KEY}, and @env{COMP_TYPE} variables are
1619 assigned values as described above (@pxref{Bash Variables}).
1620 If a shell function is being invoked, the @env{COMP_WORDS} and
1621 @env{COMP_CWORD} variables are also set.
1622 When the function or command is invoked, the first argument is the
1623 name of the command whose arguments are being completed, the
1624 second argument is the word being completed, and the third argument
1625 is the word preceding the word being completed on the current command line.
1626 No filtering of the generated completions against the word being completed
1627 is performed; the function or command has complete freedom in generating
1628 the matches.
1629
1630 Any function specified with @option{-F} is invoked first.
1631 The function may use any of the shell facilities, including the
1632 @code{compgen} and @code{compopt} builtins described below
1633 (@pxref{Programmable Completion Builtins}), to generate the matches.
1634 It must put the possible completions in the @env{COMPREPLY} array
1635 variable.
1636
1637 Next, any command specified with the @option{-C} option is invoked
1638 in an environment equivalent to command substitution.
1639 It should print a list of completions, one per line, to
1640 the standard output.
1641 Backslash may be used to escape a newline, if necessary.
1642
1643 After all of the possible completions are generated, any filter
1644 specified with the @option{-X} option is applied to the list.
1645 The filter is a pattern as used for pathname expansion; a @samp{&}
1646 in the pattern is replaced with the text of the word being completed.
1647 A literal @samp{&} may be escaped with a backslash; the backslash
1648 is removed before attempting a match.
1649 Any completion that matches the pattern will be removed from the list.
1650 A leading @samp{!} negates the pattern; in this case any completion
1651 not matching the pattern will be removed.
1652
1653 Finally, any prefix and suffix specified with the @option{-P} and @option{-S}
1654 options are added to each member of the completion list, and the result is
1655 returned to the Readline completion code as the list of possible
1656 completions.
1657
1658 If the previously-applied actions do not generate any matches, and the
1659 @option{-o dirnames} option was supplied to @code{complete} when the
1660 compspec was defined, directory name completion is attempted. 
1661
1662 If the @option{-o plusdirs} option was supplied to @code{complete} when
1663 the compspec was defined, directory name completion is attempted and any
1664 matches are added to the results of the other actions.
1665
1666 By default, if a compspec is found, whatever it generates is returned to
1667 the completion code as the full set of possible completions.
1668 The default Bash completions are not attempted, and the Readline default
1669 of filename completion is disabled.
1670 If the @option{-o bashdefault} option was supplied to @code{complete} when
1671 the compspec was defined, the default Bash completions are attempted
1672 if the compspec generates no matches.
1673 If the @option{-o default} option was supplied to @code{complete} when the
1674 compspec was defined, Readline's default completion will be performed
1675 if the compspec (and, if attempted, the default Bash completions)
1676 generate no matches.
1677
1678 When a compspec indicates that directory name completion is desired,
1679 the programmable completion functions force Readline to append a slash
1680 to completed names which are symbolic links to directories, subject to
1681 the value of the @var{mark-directories} Readline variable, regardless
1682 of the setting of the @var{mark-symlinked-directories} Readline variable.
1683
1684 @node Programmable Completion Builtins
1685 @section Programmable Completion Builtins
1686 @cindex completion builtins
1687
1688 Two builtin commands are available to manipulate the programmable completion
1689 facilities.
1690
1691 @table @code
1692 @item compgen
1693 @btindex compgen
1694 @example
1695 @code{compgen [@var{option}] [@var{word}]}
1696 @end example
1697
1698 Generate possible completion matches for @var{word} according to
1699 the @var{option}s, which may be any option accepted by the
1700 @code{complete}
1701 builtin with the exception of @option{-p} and @option{-r}, and write
1702 the matches to the standard output.
1703 When using the @option{-F} or @option{-C} options, the various shell variables
1704 set by the programmable completion facilities, while available, will not
1705 have useful values.
1706
1707 The matches will be generated in the same way as if the programmable
1708 completion code had generated them directly from a completion specification
1709 with the same flags.
1710 If @var{word} is specified, only those completions matching @var{word}
1711 will be displayed.
1712
1713 The return value is true unless an invalid option is supplied, or no
1714 matches were generated.
1715
1716 @item complete
1717 @btindex complete
1718 @example
1719 @code{complete [-abcdefgjksuv] [-o @var{comp-option}] [-E] [-A @var{action}] [-G @var{globpat}] [-W @var{wordlist}]
1720 [-F @var{function}] [-C @var{command}] [-X @var{filterpat}]
1721 [-P @var{prefix}] [-S @var{suffix}] @var{name} [@var{name} @dots{}]}
1722 @code{complete -pr [-E] [@var{name} @dots{}]}
1723 @end example
1724
1725 Specify how arguments to each @var{name} should be completed.
1726 If the @option{-p} option is supplied, or if no options are supplied, existing
1727 completion specifications are printed in a way that allows them to be
1728 reused as input.
1729 The @option{-r} option removes a completion specification for
1730 each @var{name}, or, if no @var{name}s are supplied, all
1731 completion specifications.
1732 The @option{-E} option indicates that the remaining options and actions should
1733 apply to ``empty'' command completion; that is, completion attempted on a 
1734 blank line.
1735
1736 The process of applying these completion specifications when word completion
1737 is attempted is described above (@pxref{Programmable Completion}).
1738
1739 Other options, if specified, have the following meanings.
1740 The arguments to the @option{-G}, @option{-W}, and @option{-X} options
1741 (and, if necessary, the @option{-P} and @option{-S} options)
1742 should be quoted to protect them from expansion before the
1743 @code{complete} builtin is invoked.
1744
1745
1746 @table @code
1747 @item -o @var{comp-option}
1748 The @var{comp-option} controls several aspects of the compspec's behavior
1749 beyond the simple generation of completions.
1750 @var{comp-option} may be one of: 
1751
1752 @table @code
1753
1754 @item bashdefault
1755 Perform the rest of the default Bash completions if the compspec
1756 generates no matches.
1757
1758 @item default
1759 Use Readline's default filename completion if the compspec generates
1760 no matches.
1761
1762 @item dirnames
1763 Perform directory name completion if the compspec generates no matches.
1764
1765 @item filenames
1766 Tell Readline that the compspec generates filenames, so it can perform any
1767 filename-specific processing (like adding a slash to directory names
1768 quoting special characters, or suppressing trailing spaces).
1769 This option is intended to be used with shell functions specified
1770 with @option{-F}.
1771
1772 @item nospace
1773 Tell Readline not to append a space (the default) to words completed at
1774 the end of the line.
1775
1776 @item plusdirs
1777 After any matches defined by the compspec are generated, 
1778 directory name completion is attempted and any
1779 matches are added to the results of the other actions.
1780
1781 @end table
1782
1783 @item -A @var{action}
1784 The @var{action} may be one of the following to generate a list of possible
1785 completions:
1786
1787 @table @code
1788 @item alias
1789 Alias names.  May also be specified as @option{-a}.
1790
1791 @item arrayvar
1792 Array variable names.
1793
1794 @item binding
1795 Readline key binding names (@pxref{Bindable Readline Commands}).
1796
1797 @item builtin
1798 Names of shell builtin commands.  May also be specified as @option{-b}.
1799
1800 @item command
1801 Command names.  May also be specified as @option{-c}.
1802
1803 @item directory
1804 Directory names.  May also be specified as @option{-d}.
1805
1806 @item disabled
1807 Names of disabled shell builtins.
1808
1809 @item enabled
1810 Names of enabled shell builtins.
1811
1812 @item export
1813 Names of exported shell variables.  May also be specified as @option{-e}.
1814
1815 @item file
1816 File names.  May also be specified as @option{-f}.
1817
1818 @item function
1819 Names of shell functions.
1820
1821 @item group
1822 Group names.  May also be specified as @option{-g}.
1823
1824 @item helptopic
1825 Help topics as accepted by the @code{help} builtin (@pxref{Bash Builtins}).
1826
1827 @item hostname
1828 Hostnames, as taken from the file specified by the
1829 @env{HOSTFILE} shell variable (@pxref{Bash Variables}).
1830
1831 @item job
1832 Job names, if job control is active.  May also be specified as @option{-j}.
1833
1834 @item keyword
1835 Shell reserved words.  May also be specified as @option{-k}.
1836
1837 @item running
1838 Names of running jobs, if job control is active.
1839
1840 @item service
1841 Service names.  May also be specified as @option{-s}.
1842
1843 @item setopt
1844 Valid arguments for the @option{-o} option to the @code{set} builtin
1845 (@pxref{The Set Builtin}).
1846
1847 @item shopt
1848 Shell option names as accepted by the @code{shopt} builtin
1849 (@pxref{Bash Builtins}).
1850
1851 @item signal
1852 Signal names.
1853
1854 @item stopped
1855 Names of stopped jobs, if job control is active.
1856
1857 @item user
1858 User names.  May also be specified as @option{-u}.
1859
1860 @item variable
1861 Names of all shell variables.  May also be specified as @option{-v}.
1862 @end table
1863
1864 @item -G @var{globpat}
1865 The filename expansion pattern @var{globpat} is expanded to generate
1866 the possible completions.
1867
1868 @item -W @var{wordlist}
1869 The @var{wordlist} is split using the characters in the
1870 @env{IFS} special variable as delimiters, and each resultant word
1871 is expanded.
1872 The possible completions are the members of the resultant list which
1873 match the word being completed.
1874
1875 @item -C @var{command}
1876 @var{command} is executed in a subshell environment, and its output is
1877 used as the possible completions.
1878
1879 @item -F @var{function}
1880 The shell function @var{function} is executed in the current shell
1881 environment.
1882 When it finishes, the possible completions are retrieved from the value
1883 of the @env{COMPREPLY} array variable.
1884
1885 @item -X @var{filterpat}
1886 @var{filterpat} is a pattern as used for filename expansion.
1887 It is applied to the list of possible completions generated by the
1888 preceding options and arguments, and each completion matching
1889 @var{filterpat} is removed from the list.
1890 A leading @samp{!} in @var{filterpat} negates the pattern; in this
1891 case, any completion not matching @var{filterpat} is removed.
1892
1893 @item -P @var{prefix}
1894 @var{prefix} is added at the beginning of each possible completion
1895 after all other options have been applied.
1896
1897 @item -S @var{suffix}
1898 @var{suffix} is appended to each possible completion
1899 after all other options have been applied.
1900 @end table
1901
1902 The return value is true unless an invalid option is supplied, an option
1903 other than @option{-p} or @option{-r} is supplied without a @var{name}
1904 argument, an attempt is made to remove a completion specification for
1905 a @var{name} for which no specification exists, or
1906 an error occurs adding a completion specification.
1907
1908 @item compopt
1909 @btindex compopt
1910 @example
1911 @code{compopt} [-o @var{option}] [+o @var{option}] [@var{name}]
1912 @end example
1913 Modify completion options for each @var{name} according to the
1914 @var{option}s, or for the currently-execution completion if no @var{name}s
1915 are supplied.
1916 If no @var{option}s are given, display the completion options for each
1917 @var{name} or the current completion.
1918 The possible values of @var{option} are those valid for the @code{complete}
1919 builtin described above.
1920
1921 The return value is true unless an invalid option is supplied, an attempt
1922 is made to modify the options for a @var{name} for which no completion
1923 specification exists, or an output error occurs.
1924
1925 @end table
1926
1927 @end ifset