Bash-4.1 distribution source
[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 echo-control-characters
478 When set to @samp{on}, on operating systems that indicate they support it,
479 readline echoes a character corresponding to a signal generated from the
480 keyboard.  The default is @samp{on}.
481
482 @item enable-keypad
483 @vindex enable-keypad
484 When set to @samp{on}, Readline will try to enable the application
485 keypad when it is called.  Some systems need this to enable the
486 arrow keys.  The default is @samp{off}.
487
488 @item enable-meta-key
489 When set to @samp{on}, Readline will try to enable any meta modifier
490 key the terminal claims to support when it is called.  On many terminals,
491 the meta key is used to send eight-bit characters.
492 The default is @samp{on}.
493
494 @item expand-tilde
495 @vindex expand-tilde
496 If set to @samp{on}, tilde expansion is performed when Readline
497 attempts word completion.  The default is @samp{off}.
498
499 @item history-preserve-point
500 @vindex history-preserve-point
501 If set to @samp{on}, the history code attempts to place the point (the
502 current cursor position) at the
503 same location on each history line retrieved with @code{previous-history}
504 or @code{next-history}.  The default is @samp{off}.
505
506 @item history-size
507 @vindex history-size
508 Set the maximum number of history entries saved in the history list.  If
509 set to zero, the number of entries in the history list is not limited.
510
511 @item horizontal-scroll-mode
512 @vindex horizontal-scroll-mode
513 This variable can be set to either @samp{on} or @samp{off}.  Setting it
514 to @samp{on} means that the text of the lines being edited will scroll
515 horizontally on a single screen line when they are longer than the width
516 of the screen, instead of wrapping onto a new screen line.  By default,
517 this variable is set to @samp{off}.
518
519 @item input-meta
520 @vindex input-meta
521 @vindex meta-flag
522 If set to @samp{on}, Readline will enable eight-bit input (it
523 will not clear the eighth bit in the characters it reads),
524 regardless of what the terminal claims it can support.  The
525 default value is @samp{off}.  The name @code{meta-flag} is a
526 synonym for this variable.
527
528 @item isearch-terminators
529 @vindex isearch-terminators
530 The string of characters that should terminate an incremental search without
531 subsequently executing the character as a command (@pxref{Searching}).
532 If this variable has not been given a value, the characters @key{ESC} and
533 @kbd{C-J} will terminate an incremental search.
534
535 @item keymap
536 @vindex keymap
537 Sets Readline's idea of the current keymap for key binding commands.
538 Acceptable @code{keymap} names are
539 @code{emacs},
540 @code{emacs-standard},
541 @code{emacs-meta},
542 @code{emacs-ctlx},
543 @code{vi},
544 @code{vi-move},
545 @code{vi-command}, and
546 @code{vi-insert}.
547 @code{vi} is equivalent to @code{vi-command}; @code{emacs} is
548 equivalent to @code{emacs-standard}.  The default value is @code{emacs}.
549 The value of the @code{editing-mode} variable also affects the
550 default keymap.
551
552 @item mark-directories
553 If set to @samp{on}, completed directory names have a slash
554 appended.  The default is @samp{on}.
555
556 @item mark-modified-lines
557 @vindex mark-modified-lines
558 This variable, when set to @samp{on}, causes Readline to display an
559 asterisk (@samp{*}) at the start of history lines which have been modified.
560 This variable is @samp{off} by default.
561
562 @item mark-symlinked-directories
563 @vindex mark-symlinked-directories
564 If set to @samp{on}, completed names which are symbolic links
565 to directories have a slash appended (subject to the value of
566 @code{mark-directories}).
567 The default is @samp{off}.
568
569 @item match-hidden-files
570 @vindex match-hidden-files
571 This variable, when set to @samp{on}, causes Readline to match files whose
572 names begin with a @samp{.} (hidden files) when performing filename
573 completion, unless the leading @samp{.} is
574 supplied by the user in the filename to be completed.
575 This variable is @samp{on} by default.
576
577 @item output-meta
578 @vindex output-meta
579 If set to @samp{on}, Readline will display characters with the
580 eighth bit set directly rather than as a meta-prefixed escape
581 sequence.  The default is @samp{off}.
582
583 @item page-completions
584 @vindex page-completions
585 If set to @samp{on}, Readline uses an internal @code{more}-like pager
586 to display a screenful of possible completions at a time.
587 This variable is @samp{on} by default.
588
589 @item print-completions-horizontally
590 If set to @samp{on}, Readline will display completions with matches
591 sorted horizontally in alphabetical order, rather than down the screen.
592 The default is @samp{off}.
593
594 @item revert-all-at-newline
595 @vindex revert-all-at-newline
596 If set to @samp{on}, Readline will undo all changes to history lines
597 before returning when @code{accept-line} is executed.  By default,
598 history lines may be modified and retain individual undo lists across
599 calls to @code{readline}.  The default is @samp{off}.
600
601 @item show-all-if-ambiguous
602 @vindex show-all-if-ambiguous
603 This alters the default behavior of the completion functions.  If
604 set to @samp{on}, 
605 words which have more than one possible completion cause the
606 matches to be listed immediately instead of ringing the bell.
607 The default value is @samp{off}.
608
609 @item show-all-if-unmodified
610 @vindex show-all-if-unmodified
611 This alters the default behavior of the completion functions in
612 a fashion similar to @var{show-all-if-ambiguous}.
613 If set to @samp{on}, 
614 words which have more than one possible completion without any
615 possible partial completion (the possible completions don't share
616 a common prefix) cause the matches to be listed immediately instead
617 of ringing the bell.
618 The default value is @samp{off}.
619
620 @item skip-completed-text
621 @vindex skip-completed-text
622 If set to @samp{on}, this alters the default completion behavior when
623 inserting a single match into the line.  It's only active when
624 performing completion in the middle of a word.  If enabled, readline
625 does not insert characters from the completion that match characters
626 after point in the word being completed, so portions of the word
627 following the cursor are not duplicated.
628 For instance, if this is enabled, attempting completion when the cursor
629 is after the @samp{e} in @samp{Makefile} will result in @samp{Makefile}
630 rather than @samp{Makefilefile}, assuming there is a single possible
631 completion.
632 The default value is @samp{off}.
633
634 @item visible-stats
635 @vindex visible-stats
636 If set to @samp{on}, a character denoting a file's type
637 is appended to the filename when listing possible
638 completions.  The default is @samp{off}.
639
640 @end table
641
642 @item Key Bindings
643 The syntax for controlling key bindings in the init file is
644 simple.  First you need to find the name of the command that you
645 want to change.  The following sections contain tables of the command
646 name, the default keybinding, if any, and a short description of what
647 the command does.
648
649 Once you know the name of the command, simply place on a line
650 in the init file the name of the key
651 you wish to bind the command to, a colon, and then the name of the
652 command.
653 There can be no space between the key name and the colon -- that will be
654 interpreted as part of the key name.
655 The name of the key can be expressed in different ways, depending on
656 what you find most comfortable.
657
658 In addition to command names, readline allows keys to be bound
659 to a string that is inserted when the key is pressed (a @var{macro}).
660
661 @ifset BashFeatures
662 The @w{@code{bind -p}} command displays Readline function names and
663 bindings in a format that can put directly into an initialization file.
664 @xref{Bash Builtins}.
665 @end ifset
666
667 @table @asis
668 @item @w{@var{keyname}: @var{function-name} or @var{macro}}
669 @var{keyname} is the name of a key spelled out in English.  For example:
670 @example
671 Control-u: universal-argument
672 Meta-Rubout: backward-kill-word
673 Control-o: "> output"
674 @end example
675
676 In the above example, @kbd{C-u} is bound to the function
677 @code{universal-argument},
678 @kbd{M-DEL} is bound to the function @code{backward-kill-word}, and
679 @kbd{C-o} is bound to run the macro
680 expressed on the right hand side (that is, to insert the text
681 @samp{> output} into the line).
682
683 A number of symbolic character names are recognized while
684 processing this key binding syntax:
685 @var{DEL},
686 @var{ESC},
687 @var{ESCAPE},
688 @var{LFD},
689 @var{NEWLINE},
690 @var{RET},
691 @var{RETURN},
692 @var{RUBOUT},
693 @var{SPACE},
694 @var{SPC},
695 and
696 @var{TAB}.
697
698 @item @w{"@var{keyseq}": @var{function-name} or @var{macro}}
699 @var{keyseq} differs from @var{keyname} above in that strings
700 denoting an entire key sequence can be specified, by placing
701 the key sequence in double quotes.  Some @sc{gnu} Emacs style key
702 escapes can be used, as in the following example, but the
703 special character names are not recognized.
704
705 @example
706 "\C-u": universal-argument
707 "\C-x\C-r": re-read-init-file
708 "\e[11~": "Function Key 1"
709 @end example
710
711 In the above example, @kbd{C-u} is again bound to the function
712 @code{universal-argument} (just as it was in the first example),
713 @samp{@kbd{C-x} @kbd{C-r}} is bound to the function @code{re-read-init-file},
714 and @samp{@key{ESC} @key{[} @key{1} @key{1} @key{~}} is bound to insert
715 the text @samp{Function Key 1}.
716
717 @end table
718
719 The following @sc{gnu} Emacs style escape sequences are available when
720 specifying key sequences:
721
722 @table @code
723 @item @kbd{\C-}
724 control prefix
725 @item @kbd{\M-}
726 meta prefix
727 @item @kbd{\e}
728 an escape character
729 @item @kbd{\\}
730 backslash
731 @item @kbd{\"}
732 @key{"}, a double quotation mark
733 @item @kbd{\'}
734 @key{'}, a single quote or apostrophe
735 @end table
736
737 In addition to the @sc{gnu} Emacs style escape sequences, a second
738 set of backslash escapes is available:
739
740 @table @code
741 @item \a
742 alert (bell)
743 @item \b
744 backspace
745 @item \d
746 delete
747 @item \f
748 form feed
749 @item \n
750 newline
751 @item \r
752 carriage return
753 @item \t
754 horizontal tab
755 @item \v
756 vertical tab
757 @item \@var{nnn}
758 the eight-bit character whose value is the octal value @var{nnn}
759 (one to three digits)
760 @item \x@var{HH}
761 the eight-bit character whose value is the hexadecimal value @var{HH}
762 (one or two hex digits)
763 @end table
764
765 When entering the text of a macro, single or double quotes must
766 be used to indicate a macro definition.
767 Unquoted text is assumed to be a function name.
768 In the macro body, the backslash escapes described above are expanded.
769 Backslash will quote any other character in the macro text,
770 including @samp{"} and @samp{'}.
771 For example, the following binding will make @samp{@kbd{C-x} \}
772 insert a single @samp{\} into the line:
773 @example
774 "\C-x\\": "\\"
775 @end example
776
777 @end table
778
779 @node Conditional Init Constructs
780 @subsection Conditional Init Constructs
781
782 Readline implements a facility similar in spirit to the conditional
783 compilation features of the C preprocessor which allows key
784 bindings and variable settings to be performed as the result
785 of tests.  There are four parser directives used.
786
787 @table @code
788 @item $if
789 The @code{$if} construct allows bindings to be made based on the
790 editing mode, the terminal being used, or the application using
791 Readline.  The text of the test extends to the end of the line;
792 no characters are required to isolate it.
793
794 @table @code
795 @item mode
796 The @code{mode=} form of the @code{$if} directive is used to test
797 whether Readline is in @code{emacs} or @code{vi} mode.
798 This may be used in conjunction
799 with the @samp{set keymap} command, for instance, to set bindings in
800 the @code{emacs-standard} and @code{emacs-ctlx} keymaps only if
801 Readline is starting out in @code{emacs} mode.
802
803 @item term
804 The @code{term=} form may be used to include terminal-specific
805 key bindings, perhaps to bind the key sequences output by the
806 terminal's function keys.  The word on the right side of the
807 @samp{=} is tested against both the full name of the terminal and
808 the portion of the terminal name before the first @samp{-}.  This
809 allows @code{sun} to match both @code{sun} and @code{sun-cmd},
810 for instance.
811
812 @item application
813 The @var{application} construct is used to include
814 application-specific settings.  Each program using the Readline
815 library sets the @var{application name}, and you can test for
816 a particular value. 
817 This could be used to bind key sequences to functions useful for
818 a specific program.  For instance, the following command adds a
819 key sequence that quotes the current or previous word in Bash:
820 @example
821 $if Bash
822 # Quote the current or previous word
823 "\C-xq": "\eb\"\ef\""
824 $endif
825 @end example
826 @end table
827
828 @item $endif
829 This command, as seen in the previous example, terminates an
830 @code{$if} command.
831
832 @item $else
833 Commands in this branch of the @code{$if} directive are executed if
834 the test fails.
835
836 @item $include
837 This directive takes a single filename as an argument and reads commands
838 and bindings from that file.
839 For example, the following directive reads from @file{/etc/inputrc}:
840 @example
841 $include /etc/inputrc
842 @end example
843 @end table
844
845 @node Sample Init File
846 @subsection Sample Init File
847
848 Here is an example of an @var{inputrc} file.  This illustrates key
849 binding, variable assignment, and conditional syntax.
850
851 @example
852 @page
853 # This file controls the behaviour of line input editing for
854 # programs that use the GNU Readline library.  Existing
855 # programs include FTP, Bash, and GDB.
856 #
857 # You can re-read the inputrc file with C-x C-r.
858 # Lines beginning with '#' are comments.
859 #
860 # First, include any systemwide bindings and variable
861 # assignments from /etc/Inputrc
862 $include /etc/Inputrc
863
864 #
865 # Set various bindings for emacs mode.
866
867 set editing-mode emacs 
868
869 $if mode=emacs
870
871 Meta-Control-h: backward-kill-word      Text after the function name is ignored
872
873 #
874 # Arrow keys in keypad mode
875 #
876 #"\M-OD":        backward-char
877 #"\M-OC":        forward-char
878 #"\M-OA":        previous-history
879 #"\M-OB":        next-history
880 #
881 # Arrow keys in ANSI mode
882 #
883 "\M-[D":        backward-char
884 "\M-[C":        forward-char
885 "\M-[A":        previous-history
886 "\M-[B":        next-history
887 #
888 # Arrow keys in 8 bit keypad mode
889 #
890 #"\M-\C-OD":       backward-char
891 #"\M-\C-OC":       forward-char
892 #"\M-\C-OA":       previous-history
893 #"\M-\C-OB":       next-history
894 #
895 # Arrow keys in 8 bit ANSI mode
896 #
897 #"\M-\C-[D":       backward-char
898 #"\M-\C-[C":       forward-char
899 #"\M-\C-[A":       previous-history
900 #"\M-\C-[B":       next-history
901
902 C-q: quoted-insert
903
904 $endif
905
906 # An old-style binding.  This happens to be the default.
907 TAB: complete
908
909 # Macros that are convenient for shell interaction
910 $if Bash
911 # edit the path
912 "\C-xp": "PATH=$@{PATH@}\e\C-e\C-a\ef\C-f"
913 # prepare to type a quoted word --
914 # insert open and close double quotes
915 # and move to just after the open quote
916 "\C-x\"": "\"\"\C-b"
917 # insert a backslash (testing backslash escapes
918 # in sequences and macros)
919 "\C-x\\": "\\"
920 # Quote the current or previous word
921 "\C-xq": "\eb\"\ef\""
922 # Add a binding to refresh the line, which is unbound
923 "\C-xr": redraw-current-line
924 # Edit variable on current line.
925 "\M-\C-v": "\C-a\C-k$\C-y\M-\C-e\C-a\C-y="
926 $endif
927
928 # use a visible bell if one is available
929 set bell-style visible
930
931 # don't strip characters to 7 bits when reading
932 set input-meta on
933
934 # allow iso-latin1 characters to be inserted rather
935 # than converted to prefix-meta sequences
936 set convert-meta off
937
938 # display characters with the eighth bit set directly
939 # rather than as meta-prefixed characters
940 set output-meta on
941
942 # if there are more than 150 possible completions for
943 # a word, ask the user if he wants to see all of them
944 set completion-query-items 150
945
946 # For FTP
947 $if Ftp
948 "\C-xg": "get \M-?"
949 "\C-xt": "put \M-?"
950 "\M-.": yank-last-arg
951 $endif
952 @end example
953
954 @node Bindable Readline Commands
955 @section Bindable Readline Commands
956
957 @menu
958 * Commands For Moving::         Moving about the line.
959 * Commands For History::        Getting at previous lines.
960 * Commands For Text::           Commands for changing text.
961 * Commands For Killing::        Commands for killing and yanking.
962 * Numeric Arguments::           Specifying numeric arguments, repeat counts.
963 * Commands For Completion::     Getting Readline to do the typing for you.
964 * Keyboard Macros::             Saving and re-executing typed characters
965 * Miscellaneous Commands::      Other miscellaneous commands.
966 @end menu
967
968 This section describes Readline commands that may be bound to key
969 sequences.
970 @ifset BashFeatures
971 You can list your key bindings by executing
972 @w{@code{bind -P}} or, for a more terse format, suitable for an
973 @var{inputrc} file, @w{@code{bind -p}}.  (@xref{Bash Builtins}.)
974 @end ifset
975 Command names without an accompanying key sequence are unbound by default.
976
977 In the following descriptions, @dfn{point} refers to the current cursor
978 position, and @dfn{mark} refers to a cursor position saved by the
979 @code{set-mark} command.
980 The text between the point and mark is referred to as the @dfn{region}.
981
982 @node Commands For Moving
983 @subsection Commands For Moving
984 @ftable @code
985 @item beginning-of-line (C-a)
986 Move to the start of the current line.
987
988 @item end-of-line (C-e)
989 Move to the end of the line.
990
991 @item forward-char (C-f)
992 Move forward a character.
993
994 @item backward-char (C-b)
995 Move back a character.
996
997 @item forward-word (M-f)
998 Move forward to the end of the next word.
999 Words are composed of letters and digits.
1000
1001 @item backward-word (M-b)
1002 Move back to the start of the current or previous word.
1003 Words are composed of letters and digits.
1004
1005 @ifset BashFeatures
1006 @item shell-forward-word ()
1007 Move forward to the end of the next word.
1008 Words are delimited by non-quoted shell metacharacters.
1009
1010 @item shell-backward-word ()
1011 Move back to the start of the current or previous word.
1012 Words are delimited by non-quoted shell metacharacters.
1013 @end ifset
1014
1015 @item clear-screen (C-l)
1016 Clear the screen and redraw the current line,
1017 leaving the current line at the top of the screen.
1018
1019 @item redraw-current-line ()
1020 Refresh the current line.  By default, this is unbound.
1021
1022 @end ftable
1023
1024 @node Commands For History
1025 @subsection Commands For Manipulating The History
1026
1027 @ftable @code
1028 @item accept-line (Newline or Return)
1029 @ifset BashFeatures
1030 Accept the line regardless of where the cursor is.
1031 If this line is
1032 non-empty, add it to the history list according to the setting of
1033 the @env{HISTCONTROL} and @env{HISTIGNORE} variables.
1034 If this line is a modified history line, then restore the history line
1035 to its original state.
1036 @end ifset
1037 @ifclear BashFeatures
1038 Accept the line regardless of where the cursor is.
1039 If this line is
1040 non-empty, it may be added to the history list for future recall with
1041 @code{add_history()}.
1042 If this line is a modified history line, the history line is restored
1043 to its original state.
1044 @end ifclear
1045
1046 @item previous-history (C-p)
1047 Move `back' through the history list, fetching the previous command.
1048
1049 @item next-history (C-n)
1050 Move `forward' through the history list, fetching the next command.
1051
1052 @item beginning-of-history (M-<)
1053 Move to the first line in the history.
1054
1055 @item end-of-history (M->)
1056 Move to the end of the input history, i.e., the line currently
1057 being entered.
1058
1059 @item reverse-search-history (C-r)
1060 Search backward starting at the current line and moving `up' through
1061 the history as necessary.  This is an incremental search.
1062
1063 @item forward-search-history (C-s)
1064 Search forward starting at the current line and moving `down' through
1065 the the history as necessary.  This is an incremental search.
1066
1067 @item non-incremental-reverse-search-history (M-p)
1068 Search backward starting at the current line and moving `up'
1069 through the history as necessary using a non-incremental search
1070 for a string supplied by the user.
1071
1072 @item non-incremental-forward-search-history (M-n)
1073 Search forward starting at the current line and moving `down'
1074 through the the history as necessary using a non-incremental search
1075 for a string supplied by the user.
1076
1077 @item history-search-forward ()
1078 Search forward through the history for the string of characters
1079 between the start of the current line and the point.
1080 This is a non-incremental search.
1081 By default, this command is unbound.
1082
1083 @item history-search-backward ()
1084 Search backward through the history for the string of characters
1085 between the start of the current line and the point.  This
1086 is a non-incremental search.  By default, this command is unbound.
1087
1088 @item yank-nth-arg (M-C-y)
1089 Insert the first argument to the previous command (usually
1090 the second word on the previous line) at point.
1091 With an argument @var{n},
1092 insert the @var{n}th word from the previous command (the words
1093 in the previous command begin with word 0).  A negative argument
1094 inserts the @var{n}th word from the end of the previous command.
1095 Once the argument @var{n} is computed, the argument is extracted
1096 as if the @samp{!@var{n}} history expansion had been specified.
1097
1098 @item yank-last-arg (M-. or M-_)
1099 Insert last argument to the previous command (the last word of the
1100 previous history entry).  With an
1101 argument, behave exactly like @code{yank-nth-arg}.
1102 Successive calls to @code{yank-last-arg} move back through the history
1103 list, inserting the last argument of each line in turn.
1104 The history expansion facilities are used to extract the last argument,
1105 as if the @samp{!$} history expansion had been specified.
1106
1107 @end ftable
1108
1109 @node Commands For Text
1110 @subsection Commands For Changing Text
1111
1112 @ftable @code
1113 @item delete-char (C-d)
1114 Delete the character at point.  If point is at the
1115 beginning of the line, there are no characters in the line, and
1116 the last character typed was not bound to @code{delete-char}, then
1117 return @sc{eof}.
1118
1119 @item backward-delete-char (Rubout)
1120 Delete the character behind the cursor.  A numeric argument means
1121 to kill the characters instead of deleting them.
1122
1123 @item forward-backward-delete-char ()
1124 Delete the character under the cursor, unless the cursor is at the
1125 end of the line, in which case the character behind the cursor is
1126 deleted.  By default, this is not bound to a key.
1127
1128 @item quoted-insert (C-q or C-v)
1129 Add the next character typed to the line verbatim.  This is
1130 how to insert key sequences like @kbd{C-q}, for example.
1131
1132 @ifclear BashFeatures
1133 @item tab-insert (M-@key{TAB})
1134 Insert a tab character.
1135 @end ifclear
1136
1137 @item self-insert (a, b, A, 1, !, @dots{})
1138 Insert yourself.
1139
1140 @item transpose-chars (C-t)
1141 Drag the character before the cursor forward over
1142 the character at the cursor, moving the
1143 cursor forward as well.  If the insertion point
1144 is at the end of the line, then this
1145 transposes the last two characters of the line.
1146 Negative arguments have no effect.
1147
1148 @item transpose-words (M-t)
1149 Drag the word before point past the word after point,
1150 moving point past that word as well.
1151 If the insertion point is at the end of the line, this transposes
1152 the last two words on the line.
1153
1154 @item upcase-word (M-u)
1155 Uppercase the current (or following) word.  With a negative argument,
1156 uppercase the previous word, but do not move the cursor.
1157
1158 @item downcase-word (M-l)
1159 Lowercase the current (or following) word.  With a negative argument,
1160 lowercase the previous word, but do not move the cursor.
1161
1162 @item capitalize-word (M-c)
1163 Capitalize the current (or following) word.  With a negative argument,
1164 capitalize the previous word, but do not move the cursor.
1165
1166 @item overwrite-mode ()
1167 Toggle overwrite mode.  With an explicit positive numeric argument,
1168 switches to overwrite mode.  With an explicit non-positive numeric
1169 argument, switches to insert mode.  This command affects only
1170 @code{emacs} mode; @code{vi} mode does overwrite differently.
1171 Each call to @code{readline()} starts in insert mode.
1172
1173 In overwrite mode, characters bound to @code{self-insert} replace
1174 the text at point rather than pushing the text to the right.
1175 Characters bound to @code{backward-delete-char} replace the character
1176 before point with a space.
1177
1178 By default, this command is unbound.
1179
1180 @end ftable
1181
1182 @node Commands For Killing
1183 @subsection Killing And Yanking
1184
1185 @ftable @code
1186
1187 @item kill-line (C-k)
1188 Kill the text from point to the end of the line.
1189
1190 @item backward-kill-line (C-x Rubout)
1191 Kill backward to the beginning of the line.
1192
1193 @item unix-line-discard (C-u)
1194 Kill backward from the cursor to the beginning of the current line.
1195
1196 @item kill-whole-line ()
1197 Kill all characters on the current line, no matter where point is.
1198 By default, this is unbound.
1199
1200 @item kill-word (M-d)
1201 Kill from point to the end of the current word, or if between
1202 words, to the end of the next word.
1203 Word boundaries are the same as @code{forward-word}.
1204
1205 @item backward-kill-word (M-@key{DEL})
1206 Kill the word behind point.
1207 Word boundaries are the same as @code{backward-word}.
1208
1209 @ifset BashFeatures
1210 @item shell-kill-word ()
1211 Kill from point to the end of the current word, or if between
1212 words, to the end of the next word.
1213 Word boundaries are the same as @code{shell-forward-word}.
1214
1215 @item backward-kill-word ()
1216 Kill the word behind point.
1217 Word boundaries are the same as @code{shell-backward-word}.
1218 @end ifset
1219
1220 @item unix-word-rubout (C-w)
1221 Kill the word behind point, using white space as a word boundary.
1222 The killed text is saved on the kill-ring.
1223
1224 @item unix-filename-rubout ()
1225 Kill the word behind point, using white space and the slash character
1226 as the word boundaries.
1227 The killed text is saved on the kill-ring.
1228
1229 @item delete-horizontal-space ()
1230 Delete all spaces and tabs around point.  By default, this is unbound.
1231
1232 @item kill-region ()
1233 Kill the text in the current region.
1234 By default, this command is unbound.
1235
1236 @item copy-region-as-kill ()
1237 Copy the text in the region to the kill buffer, so it can be yanked
1238 right away.  By default, this command is unbound.
1239
1240 @item copy-backward-word ()
1241 Copy the word before point to the kill buffer.
1242 The word boundaries are the same as @code{backward-word}.
1243 By default, this command is unbound.
1244
1245 @item copy-forward-word ()
1246 Copy the word following point to the kill buffer.
1247 The word boundaries are the same as @code{forward-word}.
1248 By default, this command is unbound.
1249
1250 @item yank (C-y)
1251 Yank the top of the kill ring into the buffer at point.
1252
1253 @item yank-pop (M-y)
1254 Rotate the kill-ring, and yank the new top.  You can only do this if
1255 the prior command is @code{yank} or @code{yank-pop}.
1256 @end ftable
1257
1258 @node Numeric Arguments
1259 @subsection Specifying Numeric Arguments
1260 @ftable @code
1261
1262 @item digit-argument (@kbd{M-0}, @kbd{M-1}, @dots{} @kbd{M--})
1263 Add this digit to the argument already accumulating, or start a new
1264 argument.  @kbd{M--} starts a negative argument.
1265
1266 @item universal-argument ()
1267 This is another way to specify an argument.
1268 If this command is followed by one or more digits, optionally with a
1269 leading minus sign, those digits define the argument.
1270 If the command is followed by digits, executing @code{universal-argument}
1271 again ends the numeric argument, but is otherwise ignored.
1272 As a special case, if this command is immediately followed by a
1273 character that is neither a digit or minus sign, the argument count
1274 for the next command is multiplied by four.
1275 The argument count is initially one, so executing this function the
1276 first time makes the argument count four, a second time makes the
1277 argument count sixteen, and so on.
1278 By default, this is not bound to a key.
1279 @end ftable
1280
1281 @node Commands For Completion
1282 @subsection Letting Readline Type For You
1283
1284 @ftable @code
1285 @item complete (@key{TAB})
1286 Attempt to perform completion on the text before point.
1287 The actual completion performed is application-specific.
1288 @ifset BashFeatures
1289 Bash attempts completion treating the text as a variable (if the
1290 text begins with @samp{$}), username (if the text begins with
1291 @samp{~}), hostname (if the text begins with @samp{@@}), or
1292 command (including aliases and functions) in turn.  If none 
1293 of these produces a match, filename completion is attempted.
1294 @end ifset
1295 @ifclear BashFeatures
1296 The default is filename completion.
1297 @end ifclear
1298
1299 @item possible-completions (M-?)
1300 List the possible completions of the text before point.
1301
1302 @item insert-completions (M-*)
1303 Insert all completions of the text before point that would have
1304 been generated by @code{possible-completions}.
1305
1306 @item menu-complete ()
1307 Similar to @code{complete}, but replaces the word to be completed
1308 with a single match from the list of possible completions.
1309 Repeated execution of @code{menu-complete} steps through the list
1310 of possible completions, inserting each match in turn.
1311 At the end of the list of completions, the bell is rung
1312 (subject to the setting of @code{bell-style})
1313 and the original text is restored.
1314 An argument of @var{n} moves @var{n} positions forward in the list
1315 of matches; a negative argument may be used to move backward
1316 through the list.
1317 This command is intended to be bound to @key{TAB}, but is unbound
1318 by default.
1319
1320 @item menu-complete-backward ()
1321 Identical to @code{menu-complete}, but moves backward through the list
1322 of possible completions, as if @code{menu-complete} had been given a
1323 negative argument.
1324
1325 @item delete-char-or-list ()
1326 Deletes the character under the cursor if not at the beginning or
1327 end of the line (like @code{delete-char}).
1328 If at the end of the line, behaves identically to
1329 @code{possible-completions}.
1330 This command is unbound by default.
1331
1332 @ifset BashFeatures
1333 @item complete-filename (M-/)
1334 Attempt filename completion on the text before point.
1335
1336 @item possible-filename-completions (C-x /)
1337 List the possible completions of the text before point,
1338 treating it as a filename.
1339
1340 @item complete-username (M-~)
1341 Attempt completion on the text before point, treating
1342 it as a username.
1343
1344 @item possible-username-completions (C-x ~)
1345 List the possible completions of the text before point,
1346 treating it as a username.
1347
1348 @item complete-variable (M-$)
1349 Attempt completion on the text before point, treating
1350 it as a shell variable.
1351
1352 @item possible-variable-completions (C-x $)
1353 List the possible completions of the text before point,
1354 treating it as a shell variable.
1355
1356 @item complete-hostname (M-@@)
1357 Attempt completion on the text before point, treating
1358 it as a hostname.
1359
1360 @item possible-hostname-completions (C-x @@)
1361 List the possible completions of the text before point,
1362 treating it as a hostname.
1363
1364 @item complete-command (M-!)
1365 Attempt completion on the text before point, treating
1366 it as a command name.  Command completion attempts to
1367 match the text against aliases, reserved words, shell
1368 functions, shell builtins, and finally executable filenames,
1369 in that order.
1370
1371 @item possible-command-completions (C-x !)
1372 List the possible completions of the text before point,
1373 treating it as a command name.
1374
1375 @item dynamic-complete-history (M-@key{TAB})
1376 Attempt completion on the text before point, comparing
1377 the text against lines from the history list for possible
1378 completion matches.
1379
1380 @item dabbrev-expand ()
1381 Attempt menu completion on the text before point, comparing
1382 the text against lines from the history list for possible
1383 completion matches.
1384
1385 @item complete-into-braces (M-@{)
1386 Perform filename completion and insert the list of possible completions
1387 enclosed within braces so the list is available to the shell
1388 (@pxref{Brace Expansion}).
1389
1390 @end ifset
1391 @end ftable
1392
1393 @node Keyboard Macros
1394 @subsection Keyboard Macros
1395 @ftable @code
1396
1397 @item start-kbd-macro (C-x ()
1398 Begin saving the characters typed into the current keyboard macro.
1399
1400 @item end-kbd-macro (C-x ))
1401 Stop saving the characters typed into the current keyboard macro
1402 and save the definition.
1403
1404 @item call-last-kbd-macro (C-x e)
1405 Re-execute the last keyboard macro defined, by making the characters
1406 in the macro appear as if typed at the keyboard.
1407
1408 @end ftable
1409
1410 @node Miscellaneous Commands
1411 @subsection Some Miscellaneous Commands
1412 @ftable @code
1413
1414 @item re-read-init-file (C-x C-r)
1415 Read in the contents of the @var{inputrc} file, and incorporate
1416 any bindings or variable assignments found there.
1417
1418 @item abort (C-g)
1419 Abort the current editing command and
1420 ring the terminal's bell (subject to the setting of
1421 @code{bell-style}).
1422
1423 @item do-uppercase-version (M-a, M-b, M-@var{x}, @dots{})
1424 If the metafied character @var{x} is lowercase, run the command
1425 that is bound to the corresponding uppercase character.
1426
1427 @item prefix-meta (@key{ESC})
1428 Metafy the next character typed.  This is for keyboards
1429 without a meta key.  Typing @samp{@key{ESC} f} is equivalent to typing
1430 @kbd{M-f}.
1431
1432 @item undo (C-_ or C-x C-u)
1433 Incremental undo, separately remembered for each line.
1434
1435 @item revert-line (M-r)
1436 Undo all changes made to this line.  This is like executing the @code{undo}
1437 command enough times to get back to the beginning.
1438
1439 @ifset BashFeatures
1440 @item tilde-expand (M-&)
1441 @end ifset
1442 @ifclear BashFeatures
1443 @item tilde-expand (M-~)
1444 @end ifclear
1445 Perform tilde expansion on the current word.
1446
1447 @item set-mark (C-@@)
1448 Set the mark to the point.  If a
1449 numeric argument is supplied, the mark is set to that position.
1450
1451 @item exchange-point-and-mark (C-x C-x)
1452 Swap the point with the mark.  The current cursor position is set to
1453 the saved position, and the old cursor position is saved as the mark.
1454
1455 @item character-search (C-])
1456 A character is read and point is moved to the next occurrence of that
1457 character.  A negative count searches for previous occurrences.
1458
1459 @item character-search-backward (M-C-])
1460 A character is read and point is moved to the previous occurrence
1461 of that character.  A negative count searches for subsequent
1462 occurrences.
1463
1464 @item skip-csi-sequence ()
1465 Read enough characters to consume a multi-key sequence such as those
1466 defined for keys like Home and End.  Such sequences begin with a
1467 Control Sequence Indicator (CSI), usually ESC-[.  If this sequence is
1468 bound to "\e[", keys producing such sequences will have no effect
1469 unless explicitly bound to a readline command, instead of inserting
1470 stray characters into the editing buffer.  This is unbound by default,
1471 but usually bound to ESC-[.
1472
1473 @item insert-comment (M-#)
1474 Without a numeric argument, the value of the @code{comment-begin}
1475 variable is inserted at the beginning of the current line.
1476 If a numeric argument is supplied, this command acts as a toggle:  if
1477 the characters at the beginning of the line do not match the value
1478 of @code{comment-begin}, the value is inserted, otherwise
1479 the characters in @code{comment-begin} are deleted from the beginning of
1480 the line.
1481 In either case, the line is accepted as if a newline had been typed.
1482 @ifset BashFeatures
1483 The default value of @code{comment-begin} causes this command
1484 to make the current line a shell comment.
1485 If a numeric argument causes the comment character to be removed, the line
1486 will be executed by the shell.
1487 @end ifset
1488
1489 @item dump-functions ()
1490 Print all of the functions and their key bindings to the
1491 Readline output stream.  If a numeric argument is supplied,
1492 the output is formatted in such a way that it can be made part
1493 of an @var{inputrc} file.  This command is unbound by default.
1494
1495 @item dump-variables ()
1496 Print all of the settable variables and their values to the
1497 Readline output stream.  If a numeric argument is supplied,
1498 the output is formatted in such a way that it can be made part
1499 of an @var{inputrc} file.  This command is unbound by default.
1500
1501 @item dump-macros ()
1502 Print all of the Readline key sequences bound to macros and the
1503 strings they output.  If a numeric argument is supplied,
1504 the output is formatted in such a way that it can be made part
1505 of an @var{inputrc} file.  This command is unbound by default.
1506
1507 @ifset BashFeatures
1508 @item glob-complete-word (M-g)
1509 The word before point is treated as a pattern for pathname expansion,
1510 with an asterisk implicitly appended.  This pattern is used to
1511 generate a list of matching file names for possible completions.
1512
1513 @item glob-expand-word (C-x *)
1514 The word before point is treated as a pattern for pathname expansion,
1515 and the list of matching file names is inserted, replacing the word.
1516 If a numeric argument is supplied, a @samp{*} is appended before
1517 pathname expansion.
1518
1519 @item glob-list-expansions (C-x g)
1520 The list of expansions that would have been generated by
1521 @code{glob-expand-word} is displayed, and the line is redrawn.
1522 If a numeric argument is supplied, a @samp{*} is appended before
1523 pathname expansion.
1524
1525 @item display-shell-version (C-x C-v)
1526 Display version information about the current instance of Bash.
1527
1528 @item shell-expand-line (M-C-e)
1529 Expand the line as the shell does.
1530 This performs alias and history expansion as well as all of the shell
1531 word expansions (@pxref{Shell Expansions}).
1532
1533 @item history-expand-line (M-^)
1534 Perform history expansion on the current line.
1535
1536 @item magic-space ()
1537 Perform history expansion on the current line and insert a space
1538 (@pxref{History Interaction}).
1539
1540 @item alias-expand-line ()
1541 Perform alias expansion on the current line (@pxref{Aliases}).
1542
1543 @item history-and-alias-expand-line ()
1544 Perform history and alias expansion on the current line.
1545
1546 @item insert-last-argument (M-. or M-_)
1547 A synonym for @code{yank-last-arg}.
1548
1549 @item operate-and-get-next (C-o)
1550 Accept the current line for execution and fetch the next line
1551 relative to the current line from the history for editing.  Any
1552 argument is ignored.
1553
1554 @item edit-and-execute-command (C-xC-e)
1555 Invoke an editor on the current command line, and execute the result as shell
1556 commands.
1557 Bash attempts to invoke
1558 @code{$VISUAL}, @code{$EDITOR}, and @code{emacs}
1559 as the editor, in that order.
1560
1561 @end ifset
1562
1563 @ifclear BashFeatures
1564 @item emacs-editing-mode (C-e)
1565 When in @code{vi} command mode, this causes a switch to @code{emacs}
1566 editing mode.
1567
1568 @item vi-editing-mode (M-C-j)
1569 When in @code{emacs} editing mode, this causes a switch to @code{vi}
1570 editing mode.
1571
1572 @end ifclear
1573
1574 @end ftable
1575
1576 @node Readline vi Mode
1577 @section Readline vi Mode
1578
1579 While the Readline library does not have a full set of @code{vi}
1580 editing functions, it does contain enough to allow simple editing
1581 of the line.  The Readline @code{vi} mode behaves as specified in
1582 the @sc{posix} 1003.2 standard.
1583
1584 @ifset BashFeatures
1585 In order to switch interactively between @code{emacs} and @code{vi}
1586 editing modes, use the @samp{set -o emacs} and @samp{set -o vi}
1587 commands (@pxref{The Set Builtin}).
1588 @end ifset
1589 @ifclear BashFeatures
1590 In order to switch interactively between @code{emacs} and @code{vi}
1591 editing modes, use the command @kbd{M-C-j} (bound to emacs-editing-mode
1592 when in @code{vi} mode and to vi-editing-mode in @code{emacs} mode).
1593 @end ifclear
1594 The Readline default is @code{emacs} mode.
1595
1596 When you enter a line in @code{vi} mode, you are already placed in
1597 `insertion' mode, as if you had typed an @samp{i}.  Pressing @key{ESC}
1598 switches you into `command' mode, where you can edit the text of the
1599 line with the standard @code{vi} movement keys, move to previous
1600 history lines with @samp{k} and subsequent lines with @samp{j}, and
1601 so forth.
1602
1603 @ifset BashFeatures
1604 @node Programmable Completion
1605 @section Programmable Completion
1606 @cindex programmable completion
1607
1608 When word completion is attempted for an argument to a command for
1609 which a completion specification (a @var{compspec}) has been defined
1610 using the @code{complete} builtin (@pxref{Programmable Completion Builtins}),
1611 the programmable completion facilities are invoked. 
1612
1613 First, the command name is identified.
1614 If a compspec has been defined for that command, the
1615 compspec is used to generate the list of possible completions for the word.
1616 If the command word is the empty string (completion attempted at the
1617 beginning of an empty line), any compspec defined with
1618 the @option{-E} option to @code{complete} is used.
1619 If the command word is a full pathname, a compspec for the full
1620 pathname is searched for first.
1621 If no compspec is found for the full pathname, an attempt is made to
1622 find a compspec for the portion following the final slash.
1623 If those searches do not result in a compspec, any compspec defined with
1624 the @option{-D} option to @code{complete} is used as the default.
1625
1626 Once a compspec has been found, it is used to generate the list of
1627 matching words.
1628 If a compspec is not found, the default Bash completion
1629 described above (@pxref{Commands For Completion}) is performed.
1630
1631 First, the actions specified by the compspec are used.
1632 Only matches which are prefixed by the word being completed are
1633 returned.
1634 When the @option{-f} or @option{-d} option is used for filename or
1635 directory name completion, the shell variable @env{FIGNORE} is
1636 used to filter the matches.
1637 @xref{Bash Variables}, for a description of @env{FIGNORE}.
1638
1639 Any completions specified by a filename expansion pattern to the
1640 @option{-G} option are generated next.
1641 The words generated by the pattern need not match the word being completed.
1642 The @env{GLOBIGNORE} shell variable is not used to filter the matches,
1643 but the @env{FIGNORE} shell variable is used.
1644
1645 Next, the string specified as the argument to the @option{-W} option
1646 is considered.
1647 The string is first split using the characters in the @env{IFS}
1648 special variable as delimiters.
1649 Shell quoting is honored.
1650 Each word is then expanded using
1651 brace expansion, tilde expansion, parameter and variable expansion,
1652 command substitution, and arithmetic expansion,
1653 as described above (@pxref{Shell Expansions}).
1654 The results are split using the rules described above
1655 (@pxref{Word Splitting}).
1656 The results of the expansion are prefix-matched against the word being
1657 completed, and the matching words become the possible completions.
1658
1659 After these matches have been generated, any shell function or command
1660 specified with the @option{-F} and @option{-C} options is invoked.
1661 When the command or function is invoked, the @env{COMP_LINE},
1662 @env{COMP_POINT}, @env{COMP_KEY}, and @env{COMP_TYPE} variables are
1663 assigned values as described above (@pxref{Bash Variables}).
1664 If a shell function is being invoked, the @env{COMP_WORDS} and
1665 @env{COMP_CWORD} variables are also set.
1666 When the function or command is invoked, the first argument is the
1667 name of the command whose arguments are being completed, the
1668 second argument is the word being completed, and the third argument
1669 is the word preceding the word being completed on the current command line.
1670 No filtering of the generated completions against the word being completed
1671 is performed; the function or command has complete freedom in generating
1672 the matches.
1673
1674 Any function specified with @option{-F} is invoked first.
1675 The function may use any of the shell facilities, including the
1676 @code{compgen} and @code{compopt} builtins described below
1677 (@pxref{Programmable Completion Builtins}), to generate the matches.
1678 It must put the possible completions in the @env{COMPREPLY} array
1679 variable.
1680
1681 Next, any command specified with the @option{-C} option is invoked
1682 in an environment equivalent to command substitution.
1683 It should print a list of completions, one per line, to
1684 the standard output.
1685 Backslash may be used to escape a newline, if necessary.
1686
1687 After all of the possible completions are generated, any filter
1688 specified with the @option{-X} option is applied to the list.
1689 The filter is a pattern as used for pathname expansion; a @samp{&}
1690 in the pattern is replaced with the text of the word being completed.
1691 A literal @samp{&} may be escaped with a backslash; the backslash
1692 is removed before attempting a match.
1693 Any completion that matches the pattern will be removed from the list.
1694 A leading @samp{!} negates the pattern; in this case any completion
1695 not matching the pattern will be removed.
1696
1697 Finally, any prefix and suffix specified with the @option{-P} and @option{-S}
1698 options are added to each member of the completion list, and the result is
1699 returned to the Readline completion code as the list of possible
1700 completions.
1701
1702 If the previously-applied actions do not generate any matches, and the
1703 @option{-o dirnames} option was supplied to @code{complete} when the
1704 compspec was defined, directory name completion is attempted. 
1705
1706 If the @option{-o plusdirs} option was supplied to @code{complete} when
1707 the compspec was defined, directory name completion is attempted and any
1708 matches are added to the results of the other actions.
1709
1710 By default, if a compspec is found, whatever it generates is returned to
1711 the completion code as the full set of possible completions.
1712 The default Bash completions are not attempted, and the Readline default
1713 of filename completion is disabled.
1714 If the @option{-o bashdefault} option was supplied to @code{complete} when
1715 the compspec was defined, the default Bash completions are attempted
1716 if the compspec generates no matches.
1717 If the @option{-o default} option was supplied to @code{complete} when the
1718 compspec was defined, Readline's default completion will be performed
1719 if the compspec (and, if attempted, the default Bash completions)
1720 generate no matches.
1721
1722 When a compspec indicates that directory name completion is desired,
1723 the programmable completion functions force Readline to append a slash
1724 to completed names which are symbolic links to directories, subject to
1725 the value of the @var{mark-directories} Readline variable, regardless
1726 of the setting of the @var{mark-symlinked-directories} Readline variable.
1727
1728 There is some support for dynamically modifying completions.  This is
1729 most useful when used in combination with a default completion specified
1730 with @option{-D}.  It's possible for shell functions executed as completion
1731 handlers to indicate that completion should be retried by returning an
1732 exit status of 124.  If a shell function returns 124, and changes
1733 the compspec associated with the command on which completion is being
1734 attempted (supplied as the first argument when the function is executed),
1735 programmable completion restarts from the beginning, with an
1736 attempt to find a compspec for that command.  This allows a set of
1737 completions to be built dynamically as completion is attempted, rather than
1738 being loaded all at once.
1739
1740 For instance, assuming that there is a library of compspecs, each kept in a
1741 file corresponding to the name of the command, the following default
1742 completion function would load completions dynamically:
1743
1744 @example
1745 _completion_loader()
1746 @{
1747         . "/etc/bash_completion.d/$1.sh" >/dev/null 2>&1 && return 124
1748 @}
1749 complete -D -F _completion_loader
1750 @end example
1751
1752 @node Programmable Completion Builtins
1753 @section Programmable Completion Builtins
1754 @cindex completion builtins
1755
1756 Two builtin commands are available to manipulate the programmable completion
1757 facilities.
1758
1759 @table @code
1760 @item compgen
1761 @btindex compgen
1762 @example
1763 @code{compgen [@var{option}] [@var{word}]}
1764 @end example
1765
1766 Generate possible completion matches for @var{word} according to
1767 the @var{option}s, which may be any option accepted by the
1768 @code{complete}
1769 builtin with the exception of @option{-p} and @option{-r}, and write
1770 the matches to the standard output.
1771 When using the @option{-F} or @option{-C} options, the various shell variables
1772 set by the programmable completion facilities, while available, will not
1773 have useful values.
1774
1775 The matches will be generated in the same way as if the programmable
1776 completion code had generated them directly from a completion specification
1777 with the same flags.
1778 If @var{word} is specified, only those completions matching @var{word}
1779 will be displayed.
1780
1781 The return value is true unless an invalid option is supplied, or no
1782 matches were generated.
1783
1784 @item complete
1785 @btindex complete
1786 @example
1787 @code{complete [-abcdefgjksuv] [-o @var{comp-option}] [-DE] [-A @var{action}] [-G @var{globpat}] [-W @var{wordlist}]
1788 [-F @var{function}] [-C @var{command}] [-X @var{filterpat}]
1789 [-P @var{prefix}] [-S @var{suffix}] @var{name} [@var{name} @dots{}]}
1790 @code{complete -pr [-DE] [@var{name} @dots{}]}
1791 @end example
1792
1793 Specify how arguments to each @var{name} should be completed.
1794 If the @option{-p} option is supplied, or if no options are supplied, existing
1795 completion specifications are printed in a way that allows them to be
1796 reused as input.
1797 The @option{-r} option removes a completion specification for
1798 each @var{name}, or, if no @var{name}s are supplied, all
1799 completion specifications.
1800 The @option{-D} option indicates that the remaining options and actions should
1801 apply to the ``default'' command completion; that is, completion attempted
1802 on a command for which no completion has previously been defined.
1803 The @option{-E} option indicates that the remaining options and actions should
1804 apply to ``empty'' command completion; that is, completion attempted on a 
1805 blank line.
1806
1807 The process of applying these completion specifications when word completion
1808 is attempted is described above (@pxref{Programmable Completion}).  The
1809 @option{-D} option takes precedence over @option{-E}.
1810
1811 Other options, if specified, have the following meanings.
1812 The arguments to the @option{-G}, @option{-W}, and @option{-X} options
1813 (and, if necessary, the @option{-P} and @option{-S} options)
1814 should be quoted to protect them from expansion before the
1815 @code{complete} builtin is invoked.
1816
1817
1818 @table @code
1819 @item -o @var{comp-option}
1820 The @var{comp-option} controls several aspects of the compspec's behavior
1821 beyond the simple generation of completions.
1822 @var{comp-option} may be one of: 
1823
1824 @table @code
1825
1826 @item bashdefault
1827 Perform the rest of the default Bash completions if the compspec
1828 generates no matches.
1829
1830 @item default
1831 Use Readline's default filename completion if the compspec generates
1832 no matches.
1833
1834 @item dirnames
1835 Perform directory name completion if the compspec generates no matches.
1836
1837 @item filenames
1838 Tell Readline that the compspec generates filenames, so it can perform any
1839 filename-specific processing (like adding a slash to directory names
1840 quoting special characters, or suppressing trailing spaces).
1841 This option is intended to be used with shell functions specified
1842 with @option{-F}.
1843
1844 @item nospace
1845 Tell Readline not to append a space (the default) to words completed at
1846 the end of the line.
1847
1848 @item plusdirs
1849 After any matches defined by the compspec are generated, 
1850 directory name completion is attempted and any
1851 matches are added to the results of the other actions.
1852
1853 @end table
1854
1855 @item -A @var{action}
1856 The @var{action} may be one of the following to generate a list of possible
1857 completions:
1858
1859 @table @code
1860 @item alias
1861 Alias names.  May also be specified as @option{-a}.
1862
1863 @item arrayvar
1864 Array variable names.
1865
1866 @item binding
1867 Readline key binding names (@pxref{Bindable Readline Commands}).
1868
1869 @item builtin
1870 Names of shell builtin commands.  May also be specified as @option{-b}.
1871
1872 @item command
1873 Command names.  May also be specified as @option{-c}.
1874
1875 @item directory
1876 Directory names.  May also be specified as @option{-d}.
1877
1878 @item disabled
1879 Names of disabled shell builtins.
1880
1881 @item enabled
1882 Names of enabled shell builtins.
1883
1884 @item export
1885 Names of exported shell variables.  May also be specified as @option{-e}.
1886
1887 @item file
1888 File names.  May also be specified as @option{-f}.
1889
1890 @item function
1891 Names of shell functions.
1892
1893 @item group
1894 Group names.  May also be specified as @option{-g}.
1895
1896 @item helptopic
1897 Help topics as accepted by the @code{help} builtin (@pxref{Bash Builtins}).
1898
1899 @item hostname
1900 Hostnames, as taken from the file specified by the
1901 @env{HOSTFILE} shell variable (@pxref{Bash Variables}).
1902
1903 @item job
1904 Job names, if job control is active.  May also be specified as @option{-j}.
1905
1906 @item keyword
1907 Shell reserved words.  May also be specified as @option{-k}.
1908
1909 @item running
1910 Names of running jobs, if job control is active.
1911
1912 @item service
1913 Service names.  May also be specified as @option{-s}.
1914
1915 @item setopt
1916 Valid arguments for the @option{-o} option to the @code{set} builtin
1917 (@pxref{The Set Builtin}).
1918
1919 @item shopt
1920 Shell option names as accepted by the @code{shopt} builtin
1921 (@pxref{Bash Builtins}).
1922
1923 @item signal
1924 Signal names.
1925
1926 @item stopped
1927 Names of stopped jobs, if job control is active.
1928
1929 @item user
1930 User names.  May also be specified as @option{-u}.
1931
1932 @item variable
1933 Names of all shell variables.  May also be specified as @option{-v}.
1934 @end table
1935
1936 @item -G @var{globpat}
1937 The filename expansion pattern @var{globpat} is expanded to generate
1938 the possible completions.
1939
1940 @item -W @var{wordlist}
1941 The @var{wordlist} is split using the characters in the
1942 @env{IFS} special variable as delimiters, and each resultant word
1943 is expanded.
1944 The possible completions are the members of the resultant list which
1945 match the word being completed.
1946
1947 @item -C @var{command}
1948 @var{command} is executed in a subshell environment, and its output is
1949 used as the possible completions.
1950
1951 @item -F @var{function}
1952 The shell function @var{function} is executed in the current shell
1953 environment.
1954 When it finishes, the possible completions are retrieved from the value
1955 of the @env{COMPREPLY} array variable.
1956
1957 @item -X @var{filterpat}
1958 @var{filterpat} is a pattern as used for filename expansion.
1959 It is applied to the list of possible completions generated by the
1960 preceding options and arguments, and each completion matching
1961 @var{filterpat} is removed from the list.
1962 A leading @samp{!} in @var{filterpat} negates the pattern; in this
1963 case, any completion not matching @var{filterpat} is removed.
1964
1965 @item -P @var{prefix}
1966 @var{prefix} is added at the beginning of each possible completion
1967 after all other options have been applied.
1968
1969 @item -S @var{suffix}
1970 @var{suffix} is appended to each possible completion
1971 after all other options have been applied.
1972 @end table
1973
1974 The return value is true unless an invalid option is supplied, an option
1975 other than @option{-p} or @option{-r} is supplied without a @var{name}
1976 argument, an attempt is made to remove a completion specification for
1977 a @var{name} for which no specification exists, or
1978 an error occurs adding a completion specification.
1979
1980 @item compopt
1981 @btindex compopt
1982 @example
1983 @code{compopt} [-o @var{option}] [-DE] [+o @var{option}] [@var{name}]
1984 @end example
1985 Modify completion options for each @var{name} according to the
1986 @var{option}s, or for the currently-execution completion if no @var{name}s
1987 are supplied.
1988 If no @var{option}s are given, display the completion options for each
1989 @var{name} or the current completion.
1990 The possible values of @var{option} are those valid for the @code{complete}
1991 builtin described above.
1992 The @option{-D} option indicates that the remaining options should
1993 apply to the ``default'' command completion; that is, completion attempted
1994 on a command for which no completion has previously been defined.
1995 The @option{-E} option indicates that the remaining options should
1996 apply to ``empty'' command completion; that is, completion attempted on a 
1997 blank line.
1998
1999 The @option{-D} option takes precedence over @option{-E}.
2000
2001 The return value is true unless an invalid option is supplied, an attempt
2002 is made to modify the options for a @var{name} for which no completion
2003 specification exists, or an output error occurs.
2004
2005 @end table
2006
2007 @end ifset