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