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