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