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