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