65111f333d9e037d01ca4e1c6b4dda103db3ccd1
[platform/upstream/bash.git] / lib / readline / doc / rluser.texinfo
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
7 This file documents the end user interface to the GNU command line
8 editing features.  It is to be an appendix to manuals for programs which
9 use these features.  There is a document entitled "readline.texinfo"
10 which contains both end-user and programmer documentation for the GNU
11 Readline Library.
12
13 Copyright (C) 1988, 1991, 1993, 1996 Free Software Foundation, Inc.
14
15 Authored by Brian Fox and Chet Ramey.
16
17 Permission is granted to process this file through Tex and print the
18 results, provided the printed document carries copying permission notice
19 identical to this one except for the removal of this paragraph (this
20 paragraph not being relevant to the printed manual).
21
22 Permission is granted to make and distribute verbatim copies of this manual
23 provided the copyright notice and this permission notice are preserved on
24 all copies.
25
26 Permission is granted to copy and distribute modified versions of this
27 manual under the conditions for verbatim copying, provided also that the
28 GNU Copyright statement is available to the distributee, and provided that
29 the entire resulting derived work is distributed under the terms of a
30 permission notice identical to this one.
31
32 Permission is granted to copy and distribute translations of this manual
33 into another language, under the above conditions for modified versions.
34 @end ignore
35
36 @comment If you are including this manual as an appendix, then set the
37 @comment variable readline-appendix.
38
39 @node Command Line Editing
40 @chapter Command Line Editing
41
42 This chapter describes the basic features of the @sc{GNU}
43 command line editing interface.
44
45 @menu
46 * Introduction and Notation::   Notation used in this text.
47 * Readline Interaction::        The minimum set of commands for editing a line.
48 * Readline Init File::          Customizing Readline from a user's view.
49 * Bindable Readline Commands::  A description of most of the Readline commands
50                                 available for binding
51 * Readline vi Mode::            A short description of how to make Readline
52                                 behave like the vi editor.
53 @end menu
54
55 @node Introduction and Notation
56 @section Introduction to Line Editing
57
58 The following paragraphs describe the notation used to represent
59 keystrokes.
60
61 The text @key{C-k} is read as `Control-K' and describes the character
62 produced when the @key{k} key is pressed while the Control key
63 is depressed.
64
65 The text @key{M-k} is read as `Meta-K' and describes the character
66 produced when the meta key (if you have one) is depressed, and the @key{k}
67 key is pressed.  If you do not have a meta key, the identical keystroke
68 can be generated by typing @key{ESC} @i{first}, and then typing @key{k}.
69 Either process is known as @dfn{metafying} the @key{k} key.
70
71 The text @key{M-C-k} is read as `Meta-Control-k' and describes the
72 character produced by @dfn{metafying} @key{C-k}.
73
74 In addition, several keys have their own names.  Specifically,
75 @key{DEL}, @key{ESC}, @key{LFD}, @key{SPC}, @key{RET}, and @key{TAB} all
76 stand for themselves when seen in this text, or in an init file
77 (@pxref{Readline Init File}).
78
79 @node Readline Interaction
80 @section Readline Interaction
81 @cindex interaction, readline
82
83 Often during an interactive session you type in a long line of text,
84 only to notice that the first word on the line is misspelled.  The
85 Readline library gives you a set of commands for manipulating the text
86 as you type it in, allowing you to just fix your typo, and not forcing
87 you to retype the majority of the line.  Using these editing commands,
88 you move the cursor to the place that needs correction, and delete or
89 insert the text of the corrections.  Then, when you are satisfied with
90 the line, you simply press @key{RETURN}.  You do not have to be at the
91 end of the line to press @key{RETURN}; the entire line is accepted
92 regardless of the location of the cursor within the line.
93
94 @menu
95 * Readline Bare Essentials::    The least you need to know about Readline.
96 * Readline Movement Commands::  Moving about the input line.
97 * Readline Killing Commands::   How to delete text, and how to get it back!
98 * Readline Arguments::          Giving numeric arguments to commands.
99 * Searching::                   Searching through previous lines.
100  @end menu
101
102 @node Readline Bare Essentials
103 @subsection Readline Bare Essentials
104 @cindex notation, readline
105 @cindex command editing
106 @cindex editing command lines
107
108 In order to enter characters into the line, simply type them.  The typed
109 character appears where the cursor was, and then the cursor moves one
110 space to the right.  If you mistype a character, you can use your
111 erase character to back up and delete the mistyped character.
112
113 Sometimes you may miss typing a character that you wanted to type, and
114 not notice your error until you have typed several other characters.  In
115 that case, you can type @key{C-b} to move the cursor to the left, and then
116 correct your mistake.  Afterwards, you can move the cursor to the right
117 with @key{C-f}.
118
119 When you add text in the middle of a line, you will notice that characters
120 to the right of the cursor are `pushed over' to make room for the text
121 that you have inserted.  Likewise, when you delete text behind the cursor,
122 characters to the right of the cursor are `pulled back' to fill in the
123 blank space created by the removal of the text.  A list of the basic bare
124 essentials for editing the text of an input line follows.
125
126 @table @asis
127 @item @key{C-b}
128 Move back one character.
129 @item @key{C-f}
130 Move forward one character.
131 @item @key{DEL}
132 Delete the character to the left of the cursor.
133 @item @key{C-d}
134 Delete the character underneath the cursor.
135 @item @w{Printing characters}
136 Insert the character into the line at the cursor.
137 @item @key{C-_}
138 Undo the last thing that you did.  You can undo all the way back to an
139 empty line.
140 @end table
141
142 @node Readline Movement Commands
143 @subsection Readline Movement Commands
144
145
146 The above table describes the most basic possible keystrokes that you need
147 in order to do editing of the input line.  For your convenience, many
148 other commands have been added in addition to @key{C-b}, @key{C-f},
149 @key{C-d}, and @key{DEL}.  Here are some commands for moving more rapidly
150 about the line.
151
152 @table @key
153 @item C-a
154 Move to the start of the line.
155 @item C-e
156 Move to the end of the line.
157 @item M-f
158 Move forward a word.
159 @item M-b
160 Move backward a word.
161 @item C-l
162 Clear the screen, reprinting the current line at the top.
163 @end table
164
165 Notice how @key{C-f} moves forward a character, while @key{M-f} moves
166 forward a word.  It is a loose convention that control keystrokes
167 operate on characters while meta keystrokes operate on words.
168
169 @node Readline Killing Commands
170 @subsection Readline Killing Commands
171
172 @cindex killing text
173 @cindex yanking text
174
175 @dfn{Killing} text means to delete the text from the line, but to save
176 it away for later use, usually by @dfn{yanking} (re-inserting)
177 it back into the line.
178 If the description for a command says that it `kills' text, then you can
179 be sure that you can get the text back in a different (or the same)
180 place later.
181
182 When you use a kill command, the text is saved in a @dfn{kill-ring}.
183 Any number of consecutive kills save all of the killed text together, so
184 that when you yank it back, you get it all.  The kill
185 ring is not line specific; the text that you killed on a previously
186 typed line is available to be yanked back later, when you are typing
187 another line.
188 @cindex kill ring
189
190 Here is the list of commands for killing text.
191
192 @table @key
193 @item C-k
194 Kill the text from the current cursor position to the end of the line.
195
196 @item M-d
197 Kill from the cursor to the end of the current word, or if between
198 words, to the end of the next word.
199
200 @item M-DEL
201 Kill from the cursor the start of the previous word, or if between
202 words, to the start of the previous word.
203
204 @item C-w
205 Kill from the cursor to the previous whitespace.  This is different than
206 @key{M-DEL} because the word boundaries differ.
207
208 @end table
209
210 And, here is how to @dfn{yank} the text back into the line.  Yanking
211 means to copy the most-recently-killed text from the kill buffer.
212
213 @table @key
214 @item C-y
215 Yank the most recently killed text back into the buffer at the cursor.
216
217 @item M-y
218 Rotate the kill-ring, and yank the new top.  You can only do this if
219 the prior command is @key{C-y} or @key{M-y}.
220 @end table
221
222 @node Readline Arguments
223 @subsection Readline Arguments
224
225 You can pass numeric arguments to Readline commands.  Sometimes the
226 argument acts as a repeat count, other times it is the @i{sign} of the
227 argument that is significant.  If you pass a negative argument to a
228 command which normally acts in a forward direction, that command will
229 act in a backward direction.  For example, to kill text back to the
230 start of the line, you might type @w{@kbd{M-- C-k}}.
231
232 The general way to pass numeric arguments to a command is to type meta
233 digits before the command.  If the first `digit' you type is a minus
234 sign (@key{-}), then the sign of the argument will be negative.  Once
235 you have typed one meta digit to get the argument started, you can type
236 the remainder of the digits, and then the command.  For example, to give
237 the @key{C-d} command an argument of 10, you could type @samp{M-1 0 C-d}.
238
239 @node Searching
240 @subsection Searching for Commands in the History
241
242 Readline provides commands for searching through the command history
243 @ifset BashFeatures
244 (@pxref{Bash History Facilities})
245 @end ifset
246 for lines containing a specified string.
247 There are two search modes:  @var{incremental} and @var{non-incremental}.
248
249 Incremental searches begin before the user has finished typing the
250 search string.
251 As each character of the search string is typed, readline displays
252 the next entry from the history matching the string typed so far.
253 An incremental search requires only as many characters as needed to
254 find the desired history entry.
255 The Escape character is used to terminate an incremental search.
256 Control-J will also terminate the search.
257 Control-G will abort an incremental search and restore the original
258 line.
259 When the search is terminated, the history entry containing the
260 search string becomes the current line.
261 To find other matching entries in the history list, type Control-S or
262 Control-R as appropriate.
263 This will search backward or forward in the history for the next
264 entry matching the search string typed so far.
265 Any other key sequence bound to a readline command will terminate
266 the search and execute that command.
267 For instance, a @code{newline} will terminate the search and accept
268 the line, thereby executing the command from the history list.
269
270 Non-incremental searches read the entire search string before starting
271 to search for matching history lines.  The search string may be
272 typed by the user or part of the contents of the current line.
273
274 @node Readline Init File
275 @section Readline Init File
276 @cindex initialization file, readline
277
278 Although the Readline library comes with a set of @code{emacs}-like
279 keybindings installed by default,
280 it is possible that you would like to use a different set
281 of keybindings.  You can customize programs that use Readline by putting
282 commands in an @dfn{inputrc} file in your home directory.  The name of this
283 @ifset BashFeatures
284 file is taken from the value of the shell variable @code{INPUTRC}.  If
285 @end ifset
286 @ifclear BashFeatures
287 file is taken from the value of the environment variable @code{INPUTRC}.  If
288 @end ifclear
289 that variable is unset, the default is @file{~/.inputrc}.
290
291 When a program which uses the Readline library starts up, the
292 init file is read, and the key bindings are set.
293
294 In addition, the @code{C-x C-r} command re-reads this init file, thus
295 incorporating any changes that you might have made to it.
296
297 @menu
298 * Readline Init File Syntax::   Syntax for the commands in the inputrc file.
299
300 * Conditional Init Constructs:: Conditional key bindings in the inputrc file.
301
302 * Sample Init File::            An example inputrc file.
303 @end menu
304
305 @node Readline Init File Syntax
306 @subsection Readline Init File Syntax
307
308 There are only a few basic constructs allowed in the
309 Readline init file.  Blank lines are ignored.
310 Lines beginning with a @samp{#} are comments.
311 Lines beginning with a @samp{$} indicate conditional
312 constructs (@pxref{Conditional Init Constructs}).  Other lines
313 denote variable settings and key bindings.
314
315 @table @asis
316 @item Variable Settings
317 You can change the state of a few variables in Readline by
318 using the @code{set} command within the init file.  Here is how you
319 would specify that you wish to use @code{vi} line editing commands:
320
321 @example
322 set editing-mode vi
323 @end example
324
325 Right now, there are only a few variables which can be set;
326 so few, in fact, that we just list them here:
327
328 @table @code
329
330 @item bell-style
331 @vindex bell-style
332 Controls what happens when Readline wants to ring the terminal bell.
333 If set to @samp{none}, Readline never rings the bell.  If set to
334 @samp{visible}, Readline uses a visible bell if one is available.
335 If set to @samp{audible} (the default), Readline attempts to ring
336 the terminal's bell.
337
338 @item comment-begin
339 @vindex comment-begin
340 The string to insert at the beginning of the line when the
341 @code{insert-comment} command is executed.  The default value
342 is @code{"#"}.
343
344 @item completion-query-items
345 @vindex completion-query-items
346 The number of possible completions that determines when the user is
347 asked whether he wants to see the list of possibilities.  If the
348 number of possible completions is greater than this value,
349 Readline will ask the user whether or not he wishes to view
350 them; otherwise, they are simply listed.  The default limit is
351 @code{100}.
352
353 @item convert-meta
354 @vindex convert-meta
355 If set to @samp{on}, Readline will convert characters with the
356 eigth bit set to an ASCII key sequence by stripping the eigth
357 bit and prepending an @key{ESC} character, converting them to a
358 meta-prefixed key sequence.  The default value is @samp{on}.
359
360 @item disable-completion
361 @vindex disable-completion
362 If set to @samp{On}, readline will inhibit word completion.
363 Completion  characters will be inserted into the line as if they had
364 been mapped to @code{self-insert}.  The default is @samp{off}.
365
366 @item editing-mode
367 @vindex editing-mode
368 The @code{editing-mode} variable controls which editing mode you are
369 using.  By default, Readline starts up in Emacs editing mode, where
370 the keystrokes are most similar to Emacs.  This variable can be
371 set to either @samp{emacs} or @samp{vi}.
372
373 @item enable-keypad
374 @vindex enable-keypad
375 When set to @samp{on}, readline will try to enable the application
376 keypad when it is called.  Some systems need this to enable the
377 arrow keys.  The default is @samp{off}.
378
379 @item expand-tilde
380 @vindex expand-tilde
381 If set to @samp{on}, tilde expansion is performed when Readline
382 attempts word completion.  The default is @samp{off}.
383
384 @item horizontal-scroll-mode
385 @vindex horizontal-scroll-mode
386 This variable can be set to either @samp{on} or @samp{off}.  Setting it
387 to @samp{on} means that the text of the lines that you edit will scroll
388 horizontally on a single screen line when they are longer than the width
389 of the screen, instead of wrapping onto a new screen line.  By default,
390 this variable is set to @samp{off}.
391
392 @item keymap
393 @vindex keymap
394 Sets Readline's idea of the current keymap for key binding commands.
395 Acceptable @code{keymap} names are
396 @code{emacs},
397 @code{emacs-standard},
398 @code{emacs-meta},
399 @code{emacs-ctlx},
400 @code{vi},
401 @code{vi-command}, and
402 @code{vi-insert}.
403 @code{vi} is equivalent to @code{vi-command}; @code{emacs} is
404 equivalent to @code{emacs-standard}.  The default value is @code{emacs}.
405 The value of the @code{editing-mode} variable also affects the
406 default keymap.
407
408 @item mark-directories
409 If set to @samp{on}, completed directory names have a slash
410 appended.  The default is @samp{on}.
411
412 @item mark-modified-lines
413 @vindex mark-modified-lines
414 This variable, when set to @samp{on}, says to display an asterisk
415 (@samp{*}) at the start of history lines which have been modified.
416 This variable is @samp{off} by default.
417
418 @item input-meta
419 @vindex input-meta
420 @vindex meta-flag
421 If set to @samp{on}, Readline will enable eight-bit input (it
422 will not strip the eighth bit from the characters it reads),
423 regardless of what the terminal claims it can support.  The
424 default value is @samp{off}.  The name @code{meta-flag} is a
425 synonym for this variable.
426
427 @item output-meta
428 @vindex output-meta
429 If set to @samp{on}, Readline will display characters with the
430 eighth bit set directly rather than as a meta-prefixed escape
431 sequence.  The default is @samp{off}.
432
433 @item show-all-if-ambiguous
434 @vindex show-all-if-ambiguous
435 This alters the default behavior of the completion functions.  If
436 set to @samp{on}, 
437 words which have more than one possible completion cause the
438 matches to be listed immediately instead of ringing the bell.
439 The default value is @samp{off}.
440
441 @item visible-stats
442 @vindex visible-stats
443 If set to @samp{on}, a character denoting a file's type
444 is appended to the filename when listing possible
445 completions.  The default is @samp{off}.
446
447 @end table
448
449 @item Key Bindings
450 The syntax for controlling key bindings in the init file is
451 simple.  First you have to know the name of the command that you
452 want to change.  The following pages contain tables of the command name,
453 the default keybinding, and a short description of what the command
454 does.
455
456 Once you know the name of the command, simply place the name of the key
457 you wish to bind the command to, a colon, and then the name of the
458 command on a line in the init file.  The name of the key
459 can be expressed in different ways, depending on which is most
460 comfortable for you.
461
462 @table @asis
463 @item @w{@var{keyname}: @var{function-name} or @var{macro}}
464 @var{keyname} is the name of a key spelled out in English.  For example:
465 @example
466 Control-u: universal-argument
467 Meta-Rubout: backward-kill-word
468 Control-o: "> output"
469 @end example
470
471 In the above example, @samp{C-u} is bound to the function
472 @code{universal-argument}, and @samp{C-o} is bound to run the macro
473 expressed on the right hand side (that is, to insert the text
474 @samp{> output} into the line).
475
476 @item @w{"@var{keyseq}": @var{function-name} or @var{macro}}
477 @var{keyseq} differs from @var{keyname} above in that strings
478 denoting an entire key sequence can be specified, by placing
479 the key sequence in double quotes.  Some GNU Emacs style key
480 escapes can be used, as in the following example, but the
481 special character names are not recognized.
482
483 @example
484 "\C-u": universal-argument
485 "\C-x\C-r": re-read-init-file
486 "\e[11~": "Function Key 1"
487 @end example
488
489 In the above example, @samp{C-u} is bound to the function
490 @code{universal-argument} (just as it was in the first example),
491 @samp{C-x C-r} is bound to the function @code{re-read-init-file}, and
492 @samp{ESC [ 1 1 ~} is bound to insert the text @samp{Function Key 1}.
493 The following escape sequences are available when specifying key
494 sequences:
495
496 @table @code
497 @item @kbd{\C-}
498 control prefix
499 @item @kbd{\M-}
500 meta prefix
501 @item @kbd{\e}
502 an escape character
503 @item @kbd{\\}
504 backslash
505 @item @kbd{\"}
506 @key{"}
507 @item @kbd{\'}
508 @key{'}
509 @end table
510
511 When entering the text of a macro, single or double quotes should
512 be used to indicate a macro definition.  Unquoted text
513 is assumed to be a function name.  Backslash
514 will quote any character in the macro text, including @samp{"}
515 and @samp{'}.
516 For example, the following binding will make @samp{C-x \}
517 insert a single @samp{\} into the line:
518 @example
519 "\C-x\\": "\\"
520 @end example
521
522 @end table
523 @end table
524
525 @node Conditional Init Constructs
526 @subsection Conditional Init Constructs
527
528 Readline implements a facility similar in spirit to the conditional
529 compilation features of the C preprocessor which allows key
530 bindings and variable settings to be performed as the result
531 of tests.  There are three parser directives used.
532
533 @table @code
534 @item $if
535 The @code{$if} construct allows bindings to be made based on the
536 editing mode, the terminal being used, or the application using
537 Readline.  The text of the test extends to the end of the line;
538 no characters are required to isolate it.
539
540 @table @code
541 @item mode
542 The @code{mode=} form of the @code{$if} directive is used to test
543 whether Readline is in @code{emacs} or @code{vi} mode.
544 This may be used in conjunction
545 with the @samp{set keymap} command, for instance, to set bindings in
546 the @code{emacs-standard} and @code{emacs-ctlx} keymaps only if
547 Readline is starting out in @code{emacs} mode.
548
549 @item term
550 The @code{term=} form may be used to include terminal-specific
551 key bindings, perhaps to bind the key sequences output by the
552 terminal's function keys.  The word on the right side of the
553 @samp{=} is tested against the full name of the terminal and the
554 portion of the terminal name before the first @samp{-}.  This
555 allows @code{sun} to match both @code{sun} and @code{sun-cmd},
556 for instance.
557
558 @item application
559 The @var{application} construct is used to include
560 application-specific settings.  Each program using the Readline
561 library sets the @var{application name}, and you can test for it. 
562 This could be used to bind key sequences to functions useful for
563 a specific program.  For instance, the following command adds a
564 key sequence that quotes the current or previous word in Bash:
565 @example
566 $if Bash
567 # Quote the current or previous word
568 "\C-xq": "\eb\"\ef\""
569 $endif
570 @end example
571 @end table
572
573 @item $endif
574 This command, as you saw in the previous example, terminates an
575 @code{$if} command.
576
577 @item $else
578 Commands in this branch of the @code{$if} directive are executed if
579 the test fails.
580 @end table
581
582 @node Sample Init File
583 @subsection Sample Init File
584
585 Here is an example of an inputrc file.  This illustrates key
586 binding, variable assignment, and conditional syntax.
587
588 @example
589 @page
590 # This file controls the behaviour of line input editing for
591 # programs that use the Gnu Readline library.  Existing programs
592 # include FTP, Bash, and Gdb.
593 #
594 # You can re-read the inputrc file with C-x C-r.
595 # Lines beginning with '#' are comments.
596 #
597 # Set various bindings for emacs mode.
598
599 set editing-mode emacs 
600
601 $if mode=emacs
602
603 Meta-Control-h: backward-kill-word      Text after the function name is ignored
604
605 #
606 # Arrow keys in keypad mode
607 #
608 #"\M-OD"        backward-char
609 #"\M-OC"        forward-char
610 #"\M-OA"        previous-history
611 #"\M-OB"        next-history
612 #
613 # Arrow keys in ANSI mode
614 #
615 "\M-[D"        backward-char
616 "\M-[C"        forward-char
617 "\M-[A"        previous-history
618 "\M-[B"        next-history
619 #
620 # Arrow keys in 8 bit keypad mode
621 #
622 #"\M-\C-OD"       backward-char
623 #"\M-\C-OC"       forward-char
624 #"\M-\C-OA"       previous-history
625 #"\M-\C-OB"       next-history
626 #
627 # Arrow keys in 8 bit ANSI mode
628 #
629 #"\M-\C-[D"       backward-char
630 #"\M-\C-[C"       forward-char
631 #"\M-\C-[A"       previous-history
632 #"\M-\C-[B"       next-history
633
634 C-q: quoted-insert
635
636 $endif
637
638 # An old-style binding.  This happens to be the default.
639 TAB: complete
640
641 # Macros that are convenient for shell interaction
642 $if Bash
643 # edit the path
644 "\C-xp": "PATH=$@{PATH@}\e\C-e\C-a\ef\C-f"
645 # prepare to type a quoted word -- insert open and close double quotes
646 # and move to just after the open quote
647 "\C-x\"": "\"\"\C-b"
648 # insert a backslash (testing backslash escapes in sequences and macros)
649 "\C-x\\": "\\"
650 # Quote the current or previous word
651 "\C-xq": "\eb\"\ef\""
652 # Add a binding to refresh the line, which is unbound
653 "\C-xr": redraw-current-line
654 # Edit variable on current line.
655 "\M-\C-v": "\C-a\C-k$\C-y\M-\C-e\C-a\C-y="
656 $endif
657
658 # use a visible bell if one is available
659 set bell-style visible
660
661 # don't strip characters to 7 bits when reading
662 set input-meta on
663
664 # allow iso-latin1 characters to be inserted rather than converted to
665 # prefix-meta sequences
666 set convert-meta off
667
668 # display characters with the eighth bit set directly rather than
669 # as meta-prefixed characters
670 set output-meta on
671
672 # if there are more than 150 possible completions for a word, ask the
673 # user if he wants to see all of them
674 set completion-query-items 150
675
676 # For FTP
677 $if Ftp
678 "\C-xg": "get \M-?"
679 "\C-xt": "put \M-?"
680 "\M-.": yank-last-arg
681 $endif
682 @end example
683
684 @node Bindable Readline Commands
685 @section Bindable Readline Commands
686
687 @menu
688 * Commands For Moving::         Moving about the line.
689 * Commands For History::        Getting at previous lines.
690 * Commands For Text::           Commands for changing text.
691 * Commands For Killing::        Commands for killing and yanking.
692 * Numeric Arguments::           Specifying numeric arguments, repeat counts.
693 * Commands For Completion::     Getting Readline to do the typing for you.
694 * Keyboard Macros::             Saving and re-executing typed characters
695 * Miscellaneous Commands::      Other miscellaneous commands.
696 @end menu
697
698 This section describes Readline commands that may be bound to key
699 sequences.
700
701 @node Commands For Moving
702 @subsection Commands For Moving
703 @ftable @code
704 @item beginning-of-line (C-a)
705 Move to the start of the current line.
706
707 @item end-of-line (C-e)
708 Move to the end of the line.
709
710 @item forward-char (C-f)
711 Move forward a character.
712
713 @item backward-char (C-b)
714 Move back a character.
715
716 @item forward-word (M-f)
717 Move forward to the end of the next word.  Words are composed of
718 letters and digits.
719
720 @item backward-word (M-b)
721 Move back to the start of this, or the previous, word.  Words are
722 composed of letters and digits.
723
724 @item clear-screen (C-l)
725 Clear the screen and redraw the current line,
726 leaving the current line at the top of the screen.
727
728 @item redraw-current-line ()
729 Refresh the current line.  By default, this is unbound.
730
731 @end ftable
732
733 @node Commands For History
734 @subsection Commands For Manipulating The History
735
736 @ftable @code
737 @item accept-line (Newline, Return)
738 @ifset BashFeatures
739 Accept the line regardless of where the cursor is.  If this line is
740 non-empty, add it to the history list according to the setting of
741 the @code{HISTCONTROL} variable.  If this line was a history
742 line, then restore the history line to its original state.
743 @end ifset
744 @ifclear BashFeatures
745 Accept the line regardless of where the cursor is.  If this line is
746 non-empty, add it to the history list.  If this line was a history
747 line, then restore the history line to its original state.
748 @end ifclear
749
750 @item previous-history (C-p)
751 Move `up' through the history list.
752
753 @item next-history (C-n)
754 Move `down' through the history list.
755
756 @item beginning-of-history (M-<)
757 Move to the first line in the history.
758
759 @item end-of-history (M->)
760 Move to the end of the input history, i.e., the line you are entering.
761
762 @item reverse-search-history (C-r)
763 Search backward starting at the current line and moving `up' through
764 the history as necessary.  This is an incremental search.
765
766 @item forward-search-history (C-s)
767 Search forward starting at the current line and moving `down' through
768 the the history as necessary.  This is an incremental search.
769
770 @item non-incremental-reverse-search-history (M-p)
771 Search backward starting at the current line and moving `up'
772 through the history as necessary using a non-incremental search
773 for a string supplied by the user.
774
775 @item non-incremental-forward-search-history (M-n)
776 Search forward starting at the current line and moving `down'
777 through the the history as necessary using a non-incremental search
778 for a string supplied by the user.
779
780 @item history-search-forward ()
781 Search forward through the history for the string of characters
782 between the start of the current line and the current cursor
783 position (the `point').  This is a non-incremental search.  By
784 default, this command is unbound.
785
786 @item history-search-backward ()
787 Search backward through the history for the string of characters
788 between the start of the current line and the point.  This
789 is a non-incremental search.  By default, this command is unbound.
790
791 @item yank-nth-arg (M-C-y)
792 Insert the first argument to the previous command (usually
793 the second word on the previous line).  With an argument @var{n},
794 insert the @var{n}th word from the previous command (the words
795 in the previous command begin with word 0).  A negative argument
796 inserts the @var{n}th word from the end of the previous command.
797
798 @item yank-last-arg (M-., M-_)
799 Insert last argument to the previous command (the last word of the
800 previous history entry).  With an
801 argument, behave exactly like @code{yank-nth-arg}.
802
803 @end ftable
804
805 @node Commands For Text
806 @subsection Commands For Changing Text
807
808 @ftable @code
809 @item delete-char (C-d)
810 Delete the character under the cursor.  If the cursor is at the
811 beginning of the line, there are no characters in the line, and
812 the last character typed was not @kbd{C-d}, then return @code{EOF}.
813
814 @item backward-delete-char (Rubout)
815 Delete the character behind the cursor.  A numeric arg says to kill
816 the characters instead of deleting them.
817
818 @item quoted-insert (C-q, C-v)
819 Add the next character that you type to the line verbatim.  This is
820 how to insert key sequences like @key{C-q}, for example.
821
822 @item tab-insert (M-TAB)
823 Insert a tab character.
824
825 @item self-insert (a, b, A, 1, !, ...)
826 Insert yourself.
827
828 @item transpose-chars (C-t)
829 Drag the character before the cursor forward over
830 the character at the cursor, moving the
831 cursor forward as well.  If the insertion point
832 is at the end of the line, then this
833 transposes the last two characters of the line.
834 Negative argumentss don't work.
835
836 @item transpose-words (M-t)
837 Drag the word behind the cursor past the word in front of the cursor
838 moving the cursor over that word as well.
839
840 @item upcase-word (M-u)
841 Uppercase the current (or following) word.  With a negative argument,
842 do the previous word, but do not move the cursor.
843
844 @item downcase-word (M-l)
845 Lowercase the current (or following) word.  With a negative argument,
846 do the previous word, but do not move the cursor.
847
848 @item capitalize-word (M-c)
849 Capitalize the current (or following) word.  With a negative argument,
850 do the previous word, but do not move the cursor.
851
852 @end ftable
853
854 @node Commands For Killing
855 @subsection Killing And Yanking
856
857 @ftable @code
858
859 @item kill-line (C-k)
860 Kill the text from the current cursor position to the end of the line.
861
862 @item backward-kill-line (C-x Rubout)
863 Kill backward to the beginning of the line.
864
865 @item unix-line-discard (C-u)
866 Kill backward from the cursor to the beginning of the current line.
867 Save the killed text on the kill-ring.
868
869 @item kill-whole-line ()
870 Kill all characters on the current line, no matter where the
871 cursor is.  By default, this is unbound.
872
873 @item kill-word (M-d)
874 Kill from the cursor to the end of the current word, or if between
875 words, to the end of the next word.  Word boundaries are the same
876 as @code{forward-word}.
877
878 @item backward-kill-word (M-DEL)
879 Kill the word behind the cursor.  Word boundaries are the same
880 as @code{backward-word}.
881
882 @item unix-word-rubout (C-w)
883 Kill the word behind the cursor, using white space as a word
884 boundary.  The killed text is saved on the kill-ring.
885
886 @item delete-horizontal-space ()
887 Delete all spaces and tabs around point.  By default, this is unbound.
888
889 @item kill-region ()
890 Kill the text between the point and the @emph{mark} (saved
891 cursor position.  This text is referred to as the @var{region}.
892 By default, this command is unbound.
893
894 @item copy-region-as-kill ()
895 Copy the text in the region to the kill buffer, so you can yank it
896 right away.  By default, this command is unbound.
897
898 @item copy-backward-word ()
899 Copy the word before point to the kill buffer.
900 By default, this command is unbound.
901
902 @item copy-forward-word ()
903 Copy the word following point to the kill buffer.
904 By default, this command is unbound.
905
906 @item yank (C-y)
907 Yank the top of the kill ring into the buffer at the current
908 cursor position.
909
910 @item yank-pop (M-y)
911 Rotate the kill-ring, and yank the new top.  You can only do this if
912 the prior command is yank or yank-pop.
913 @end ftable
914
915 @node Numeric Arguments
916 @subsection Specifying Numeric Arguments
917 @ftable @code
918
919 @item digit-argument (M-0, M-1, ... M--)
920 Add this digit to the argument already accumulating, or start a new
921 argument.  @key{M--} starts a negative argument.
922
923 @item universal-argument ()
924 Each time this is executed, the argument count is multiplied by four.
925 The argument count is initially one, so executing this function the
926 first time makes the argument count four.  By default, this is not
927 bound to a key.
928 @end ftable
929
930 @node Commands For Completion
931 @subsection Letting Readline Type For You
932
933 @ftable @code
934 @item complete (TAB)
935 Attempt to do completion on the text before the cursor.  This is
936 application-specific.  Generally, if you are typing a filename
937 argument, you can do filename completion; if you are typing a command,
938 you can do command completion, if you are typing in a symbol to GDB, you
939 can do symbol name completion, if you are typing in a variable to Bash,
940 you can do variable name completion, and so on.
941 @ifset BashFeatures
942 Bash attempts completion treating the text as a variable (if the
943 text begins with @samp{$}), username (if the text begins with
944 @samp{~}), hostname (if the text begins with @samp{@@}), or
945 command (including aliases and functions) in turn.  If none 
946 of these produces a match, filename completion is attempted.
947 @end ifset
948
949 @item possible-completions (M-?)
950 List the possible completions of the text before the cursor.
951
952 @item insert-completions (M-*)
953 Insert all completions of the text before point that would have
954 been generated by @code{possible-completions}.
955
956 @ifset BashFeatures
957 @item complete-filename (M-/)
958 Attempt filename completion on the text before point.
959
960 @item possible-filename-completions (C-x /)
961 List the possible completions of the text before point,
962 treating it as a filename.
963
964 @item complete-username (M-~)
965 Attempt completion on the text before point, treating
966 it as a username.
967
968 @item possible-username-completions (C-x ~)
969 List the possible completions of the text before point,
970 treating it as a username.
971
972 @item complete-variable (M-$)
973 Attempt completion on the text before point, treating
974 it as a shell variable.
975
976 @item possible-variable-completions (C-x $)
977 List the possible completions of the text before point,
978 treating it as a shell variable.
979
980 @item complete-hostname (M-@@)
981 Attempt completion on the text before point, treating
982 it as a hostname.
983
984 @item possible-hostname-completions (C-x @@)
985 List the possible completions of the text before point,
986 treating it as a hostname.
987
988 @item complete-command (M-!)
989 Attempt completion on the text before point, treating
990 it as a command name.  Command completion attempts to
991 match the text against aliases, reserved words, shell
992 functions, builtins, and finally executable filenames,
993 in that order.
994
995 @item possible-command-completions (C-x !)
996 List the possible completions of the text before point,
997 treating it as a command name.
998
999 @item dynamic-complete-history (M-TAB)
1000 Attempt completion on the text before point, comparing
1001 the text against lines from the history list for possible
1002 completion matches.
1003
1004 @item complete-into-braces (M-@{)
1005 Perform filename completion and return the list of possible completions
1006 enclosed within braces so the list is available to the shell
1007 (@pxref{Brace Expansion}).
1008
1009 @end ifset
1010 @end ftable
1011
1012 @node Keyboard Macros
1013 @subsection Keyboard Macros
1014 @ftable @code
1015
1016 @item start-kbd-macro (C-x ()
1017 Begin saving the characters typed into the current keyboard macro.
1018
1019 @item end-kbd-macro (C-x ))
1020 Stop saving the characters typed into the current keyboard macro
1021 and save the definition.
1022
1023 @item call-last-kbd-macro (C-x e)
1024 Re-execute the last keyboard macro defined, by making the characters
1025 in the macro appear as if typed at the keyboard.
1026
1027 @end ftable
1028
1029 @node Miscellaneous Commands
1030 @subsection Some Miscellaneous Commands
1031 @ftable @code
1032
1033 @item re-read-init-file (C-x C-r)
1034 Read in the contents of the inputrc file, and incorporate
1035 any bindings or variable assignments found there.
1036
1037 @item abort (C-g)
1038 Abort the current editing command and
1039 ring the terminal's bell (subject to the setting of
1040 @code{bell-style}).
1041
1042 @item do-uppercase-version (M-a, M-b, M-@var{x}, @dots{})
1043 If the metafied character @var{x} is lowercase, run the command
1044 that is bound to the corresponding uppercase character.
1045
1046 @item prefix-meta (ESC)
1047 Make the next character that you type be metafied.  This is for people
1048 without a meta key.  Typing @samp{ESC f} is equivalent to typing
1049 @samp{M-f}.
1050
1051 @item undo (C-_, C-x C-u)
1052 Incremental undo, separately remembered for each line.
1053
1054 @item revert-line (M-r)
1055 Undo all changes made to this line.  This is like typing the @code{undo}
1056 command enough times to get back to the beginning.
1057
1058 @item tilde-expand (M-~)
1059 Perform tilde expansion on the current word.
1060
1061 @item set-mark (C-@@)
1062 Set the mark to the current point.  If a
1063 numeric argument is supplied, the mark is set to that position.
1064
1065 @item exchange-point-and-mark (C-x C-x)
1066 Swap the point with the mark.  The current cursor position is set to
1067 the saved position, and the old cursor position is saved as the mark.
1068
1069 @item character-search (C-])
1070 A character is read and point is moved to the next occurrence of that
1071 character.  A negative count searches for previous occurrences.
1072
1073 @item character-search-backward (M-C-])
1074 A character is read and point is moved to the previous occurrence
1075 of that character.  A negative count searches for subsequent
1076 occurrences.
1077
1078 @item insert-comment (M-#)
1079 The value of the @code{comment-begin}
1080 variable is inserted at the beginning of the current line,
1081 and the line is accepted as if a newline had been typed.
1082 @ifset BashFeatures
1083 This makes the current line a shell comment.
1084 @end ifset
1085
1086 @item dump-functions ()
1087 Print all of the functions and their key bindings to the
1088 readline output stream.  If a numeric argument is supplied,
1089 the output is formatted in such a way that it can be made part
1090 of an @var{inputrc} file.  This command is unbound by default.
1091
1092 @item dump-variables ()
1093 Print all of the settable variables and their values to the
1094 readline output stream.  If a numeric argument is supplied,
1095 the output is formatted in such a way that it can be made part
1096 of an @var{inputrc} file.  This command is unbound by default.
1097
1098 @item dump-macros ()
1099 Print all of the readline key sequences bound to macros and the
1100 strings they ouput.  If a numeric argument is supplied,
1101 the output is formatted in such a way that it can be made part
1102 of an @var{inputrc} file.  This command is unbound by default.
1103
1104 @ifset BashFeatures
1105 @item glob-expand-word (C-x *)
1106 The word before point is treated as a pattern for pathname expansion,
1107 and the list of matching file names is inserted, replacing the word.
1108
1109 @item glob-list-expansions (C-x g)
1110 The list of expansions that would have been generated by
1111 @code{glob-expand-word}
1112 is inserted into the line, replacing the word before point.
1113
1114 @item display-shell-version (C-x C-v)
1115 Display version information about the current instance of Bash.
1116
1117 @item shell-expand-line (M-C-e)
1118 Expand the line the way the shell does when it reads it.  This
1119 performs alias and history expansion as well as all of the shell
1120 word expansions.
1121
1122 @item history-expand-line (M-^)
1123 Perform history expansion on the current line.
1124
1125 @item insert-last-argument (M-., M-_)
1126 A synonym for @code{yank-last-arg}.
1127
1128 @item operate-and-get-next (C-o)
1129 Accept the current line for execution and fetch the next line
1130 relative to the current line from the history for editing.  Any
1131 argument is ignored.
1132
1133 @item emacs-editing-mode (C-e)
1134 When in @code{vi} editing mode, this causes a switch back to
1135 @code{emacs} editing mode, as if the command @samp{set -o emacs} had
1136 been executed.
1137
1138 @end ifset
1139
1140 @end ftable
1141
1142 @node Readline vi Mode
1143 @section Readline vi Mode
1144
1145 While the Readline library does not have a full set of @code{vi}
1146 editing functions, it does contain enough to allow simple editing
1147 of the line.  The Readline @code{vi} mode behaves as specified in
1148 the @sc{POSIX} 1003.2 standard.
1149
1150 @ifset BashFeatures
1151 In order to switch interactively between @code{emacs} and @code{vi}
1152 editing modes, use the @samp{set -o emacs} and @samp{set -o vi}
1153 commands (@pxref{The Set Builtin}).
1154 @end ifset
1155 @ifclear BashFeatures
1156 In order to switch interactively between @code{emacs} and @code{vi}
1157 editing modes, use the command M-C-j (toggle-editing-mode).
1158 @end ifclear
1159 The Readline default is @code{emacs} mode.
1160
1161 When you enter a line in @code{vi} mode, you are already placed in
1162 `insertion' mode, as if you had typed an @samp{i}.  Pressing @key{ESC}
1163 switches you into `command' mode, where you can edit the text of the
1164 line with the standard @code{vi} movement keys, move to previous
1165 history lines with @samp{k} and subsequent lines with @samp{j}, and
1166 so forth.