Formatting improvements from 93q4 release.
[platform/upstream/binutils.git] / readline / doc / rluser.texinfo
1 @ignore
2 This file documents the end user interface to the GNU command line
3 editing feautres.  It is to be an appendix to manuals for programs which
4 use these features.  There is a document entitled "readline.texinfo"
5 which contains both end-user and programmer documentation for the GNU
6 Readline Library.
7
8 Copyright (C) 1988 Free Software Foundation, Inc.
9
10 Authored by Brian Fox.
11
12 Permission is granted to process this file through Tex and print the
13 results, provided the printed document carries copying permission notice
14 identical to this one except for the removal of this paragraph (this
15 paragraph not being relevant to the printed manual).
16
17 Permission is granted to make and distribute verbatim copies of this manual
18 provided the copyright notice and this permission notice are preserved on
19 all copies.
20
21 Permission is granted to copy and distribute modified versions of this
22 manual under the conditions for verbatim copying, provided also that the
23 GNU Copyright statement is available to the distributee, and provided that
24 the entire resulting derived work is distributed under the terms of a
25 permission notice identical to this one.
26
27 Permission is granted to copy and distribute translations of this manual
28 into another language, under the above conditions for modified versions.
29 @end ignore
30
31 @node Command Line Editing
32 @appendix Command Line Editing
33
34 This text describes GNU's command line editing interface.
35
36 @menu
37 * Introduction and Notation::   Notation used in this text.
38 * Readline Interaction::        The minimum set of commands for editing a line.
39 * Readline Init File::          Customizing Readline from a user's view.
40 @end menu
41
42 @node Introduction and Notation
43 @section Introduction to Line Editing
44
45 The following paragraphs describe the notation we use to represent
46 keystrokes.
47
48 The text @key{C-k} is read as `Control-K' and describes the character
49 produced when the Control key is depressed and the @key{k} key is struck.
50
51 The text @key{M-k} is read as `Meta-K' and describes the character
52 produced when the meta key (if you have one) is depressed, and the @key{k}
53 key is struck.  If you do not have a meta key, the identical keystroke
54 can be generated by typing @key{ESC} @i{first}, and then typing @key{k}.
55 Either process is known as @dfn{metafying} the @key{k} key.
56
57 The text @key{M-C-k} is read as `Meta-Control-k' and describes the
58 character produced by @dfn{metafying} @key{C-k}.
59
60 In addition, several keys have their own names.  Specifically,
61 @key{DEL}, @key{ESC}, @key{LFD}, @key{SPC}, @key{RET}, and @key{TAB} all
62 stand for themselves when seen in this text, or in an init file
63 (@pxref{Readline Init File}, for more info).
64
65 @node Readline Interaction
66 @section Readline Interaction
67 @cindex interaction, readline
68
69 Often during an interactive session you type in a long line of text,
70 only to notice that the first word on the line is misspelled.  The
71 Readline library gives you a set of commands for manipulating the text
72 as you type it in, allowing you to just fix your typo, and not forcing
73 you to retype the majority of the line.  Using these editing commands,
74 you move the cursor to the place that needs correction, and delete or
75 insert the text of the corrections.  Then, when you are satisfied with
76 the line, you simply press @key{RETURN}.  You do not have to be at the
77 end of the line to press @key{RETURN}; the entire line is accepted
78 regardless of the location of the cursor within the line.
79
80 @menu
81 * Readline Bare Essentials::    The least you need to know about Readline.
82 * Readline Movement Commands::  Moving about the input line.
83 * Readline Killing Commands::   How to delete text, and how to get it back!
84 * Readline Arguments::          Giving numeric arguments to commands.
85 @end menu
86
87 @node Readline Bare Essentials
88 @subsection Readline Bare Essentials
89
90 In order to enter characters into the line, simply type them.  The typed
91 character appears where the cursor was, and then the cursor moves one
92 space to the right.  If you mistype a character, you can use @key{DEL} to
93 back up, and delete the mistyped character.
94
95 Sometimes you may miss typing a character that you wanted to type, and
96 not notice your error until you have typed several other characters.  In
97 that case, you can type @key{C-b} to move the cursor to the left, and then
98 correct your mistake.  Aftwerwards, you can move the cursor to the right
99 with @key{C-f}.
100
101 When you add text in the middle of a line, you will notice that characters
102 to the right of the cursor get `pushed over' to make room for the text
103 that you have inserted.  Likewise, when you delete text behind the cursor,
104 characters to the right of the cursor get `pulled back' to fill in the
105 blank space created by the removal of the text.  A list of the basic bare
106 essentials for editing the text of an input line follows.
107
108 @table @asis
109 @item @key{C-b}
110 Move back one character.
111 @item @key{C-f}
112 Move forward one character.
113 @item @key{DEL}
114 Delete the character to the left of the cursor.
115 @item @key{C-d}
116 Delete the character underneath the cursor.
117 @item @w{Printing characters}
118 Insert itself into the line at the cursor.
119 @item @key{C-_}
120 Undo the last thing that you did.  You can undo all the way back to an
121 empty line.
122 @end table
123
124 @node Readline Movement Commands
125 @subsection Readline Movement Commands
126
127 The above table describes the most basic possible keystrokes that you need
128 in order to do editing of the input line.  For your convenience, many
129 other commands have been added in addition to @key{C-b}, @key{C-f},
130 @key{C-d}, and @key{DEL}.  Here are some commands for moving more rapidly
131 about the line.
132
133 @table @key
134 @item C-a
135 Move to the start of the line.
136 @item C-e
137 Move to the end of the line.
138 @item M-f
139 Move forward a word.
140 @item M-b
141 Move backward a word.
142 @item C-l
143 Clear the screen, reprinting the current line at the top.
144 @end table
145
146 Notice how @key{C-f} moves forward a character, while @key{M-f} moves
147 forward a word.  It is a loose convention that control keystrokes
148 operate on characters while meta keystrokes operate on words.
149
150 @node Readline Killing Commands
151 @subsection Readline Killing Commands
152
153 @dfn{Killing} text means to delete the text from the line, but to save
154 it away for later use, usually by @dfn{yanking} it back into the line.
155 If the description for a command says that it `kills' text, then you can
156 be sure that you can get the text back in a different (or the same)
157 place later.
158
159 Here is the list of commands for killing text.
160
161 @table @key
162 @item C-k
163 Kill the text from the current cursor position to the end of the line.
164
165 @item M-d
166 Kill from the cursor to the end of the current word, or if between
167 words, to the end of the next word.
168
169 @item M-DEL
170 Kill from the cursor to the start of the previous word, or if between
171 words, to the start of the previous word. 
172
173 @item C-w
174 Kill from the cursor to the previous whitespace.  This is different than
175 @key{M-DEL} because the word boundaries differ.
176
177 @end table
178
179 And, here is how to @dfn{yank} the text back into the line.  Yanking
180 is
181
182 @table @key
183 @item C-y
184 Yank the most recently killed text back into the buffer at the cursor.
185
186 @item M-y
187 Rotate the kill-ring, and yank the new top.  You can only do this if
188 the prior command is @key{C-y} or @key{M-y}.
189 @end table
190
191 When you use a kill command, the text is saved in a @dfn{kill-ring}.
192 Any number of consecutive kills save all of the killed text together, so
193 that when you yank it back, you get it in one clean sweep.  The kill
194 ring is not line specific; the text that you killed on a previously
195 typed line is available to be yanked back later, when you are typing
196 another line.
197
198 @node Readline Arguments
199 @subsection Readline Arguments
200
201 You can pass numeric arguments to Readline commands.  Sometimes the
202 argument acts as a repeat count, other times it is the @i{sign} of the
203 argument that is significant.  If you pass a negative argument to a
204 command which normally acts in a forward direction, that command will
205 act in a backward direction.  For example, to kill text back to the
206 start of the line, you might type @key{M--} @key{C-k}.
207
208 The general way to pass numeric arguments to a command is to type meta
209 digits before the command.  If the first `digit' you type is a minus
210 sign (@key{-}), then the sign of the argument will be negative.  Once
211 you have typed one meta digit to get the argument started, you can type
212 the remainder of the digits, and then the command.  For example, to give
213 the @key{C-d} command an argument of 10, you could type @key{M-1 0 C-d}.
214
215
216 @node Readline Init File
217 @section Readline Init File
218
219 Although the Readline library comes with a set of Emacs-like
220 keybindings, it is possible that you would like to use a different set
221 of keybindings.  You can customize programs that use Readline by putting
222 commands in an @dfn{init} file in your home directory.  The name of this
223 file is @file{~/.inputrc}.
224
225 When a program which uses the Readline library starts up, the
226 @file{~/.inputrc} file is read, and the keybindings are set.
227
228 In addition, the @key{C-x C-r} command re-reads this init file, thus
229 incorporating any changes that you might have made to it.
230
231 @menu
232 * Readline Init Syntax::        Syntax for the commands in @file{~/.inputrc}.
233 * Readline Vi Mode::            Switching to @code{vi} mode in Readline.
234 @end menu
235
236 @node Readline Init Syntax
237 @subsection Readline Init Syntax
238
239 There are only four constructs allowed in the @file{~/.inputrc}
240 file:
241
242 @table @asis
243 @item Variable Settings
244 You can change the state of a few variables in Readline.  You do this by
245 using the @code{set} command within the init file.  Here is how you
246 would specify that you wish to use Vi line editing commands:
247
248 @example
249 set editing-mode vi
250 @end example
251
252 Right now, there are only a few variables which can be set; so few in
253 fact, that we just iterate them here:
254
255 @table @code
256
257 @item editing-mode
258 @vindex editing-mode
259 The @code{editing-mode} variable controls which editing mode you are
260 using.  By default, GNU Readline starts up in Emacs editing mode, where
261 the keystrokes are most similar to Emacs.  This variable can either be
262 set to @code{emacs} or @code{vi}.
263
264 @item horizontal-scroll-mode
265 @vindex horizontal-scroll-mode
266 This variable can either be set to @code{On} or @code{Off}.  Setting it
267 to @code{On} means that the text of the lines that you edit will scroll
268 horizontally on a single screen line when they are larger than the width
269 of the screen, instead of wrapping onto a new screen line.  By default,
270 this variable is set to @code{Off}.
271
272 @item mark-modified-lines
273 @vindex mark-modified-lines
274 This variable when set to @code{On}, says to display an asterisk
275 (@samp{*}) at the starts of history lines which have been modified.
276 This variable is off by default.
277
278 @item prefer-visible-bell
279 @vindex prefer-visible-bell
280 If this variable is set to @code{On} it means to use a visible bell if
281 one is available, rather than simply ringing the terminal bell.  By
282 default, the value is @code{Off}.
283 @end table
284
285 @item Key Bindings
286 The syntax for controlling keybindings in the @file{~/.inputrc} file is
287 simple.  First you have to know the @i{name} of the command that you
288 want to change.  The following pages contain tables of the command name,
289 the default keybinding, and a short description of what the command
290 does.
291
292 Once you know the name of the command, simply place the name of the key
293 you wish to bind the command to, a colon, and then the name of the
294 command on a line in the @file{~/.inputrc} file.  The name of the key
295 can be expressed in different ways, depending on which is most
296 comfortable for you.
297
298 @table @asis
299 @item @w{@var{keyname}: @var{function-name} or @var{macro}}
300 @var{keyname} is the name of a key spelled out in English.  For example:
301 @example
302 Control-u: universal-argument
303 Meta-Rubout: backward-kill-word
304 Control-o: ">&output"
305 @end example
306
307 In the above example, @key{C-u} is bound to the function
308 @code{universal-argument}, and @key{C-o} is bound to run the macro
309 expressed on the right hand side (that is, to insert the text
310 @samp{>&output} into the line).
311
312 @item @w{"@var{keyseq}": @var{function-name} or @var{macro}}
313 @var{keyseq} differs from @var{keyname} above in that strings denoting
314 an entire key sequence can be specified.  Simply place the key sequence
315 in double quotes.  GNU Emacs style key escapes can be used, as in the
316 following example:
317
318 @example
319 "\C-u": universal-argument
320 "\C-x\C-r": re-read-init-file
321 "\e[11~": "Function Key 1"
322 @end example
323
324 In the above example, @key{C-u} is bound to the function
325 @code{universal-argument} (just as it was in the first example),
326 @key{C-x C-r} is bound to the function @code{re-read-init-file}, and
327 @key{ESC [ 1 1 ~} is bound to insert the text @samp{Function Key 1}.
328
329 @end table
330 @end table
331
332 @menu
333 * Commands For Moving::         Moving about the line.
334 * Commands For History::        Getting at previous lines.
335 * Commands For Text::           Commands for changing text.
336 * Commands For Killing::        Commands for killing and yanking.
337 * Numeric Arguments::           Specifying numeric arguments, repeat counts.
338 * Commands For Completion::     Getting Readline to do the typing for you.
339 * Miscellaneous Commands::      Other miscillaneous commands.
340 @end menu
341
342 @need 2000
343 @node Commands For Moving
344 @subsubsection Commands For Moving
345
346 @ftable @code
347 @item beginning-of-line (@key{C-a})
348 Move to the start of the current line.
349
350 @item end-of-line (@key{C-e})
351 Move to the end of the line.
352
353 @item forward-char (@key{C-f})
354 Move forward a character.
355
356 @item backward-char (@key{C-b})
357 Move back a character.
358
359 @item forward-word (@key{M-f})
360 Move forward to the end of the next word.
361
362 @item backward-word (@key{M-b})
363 Move back to the start of this, or the previous, word.
364
365 @item clear-screen (@key{C-l})
366 Clear the screen leaving the current line at the top of the screen.
367
368 @end ftable
369
370 @need 2000
371 @node Commands For History
372 @subsubsection Commands For Manipulating The History
373
374 @ftable @code
375 @item accept-line (Newline, Return)
376 Accept the line regardless of where the cursor is.  If this line is
377 non-empty, add it to the history list.  If this line was a history
378 line, then restore the history line to its original state.
379
380 @item previous-history (@key{C-p})
381 Move `up' through the history list.
382
383 @item next-history (@key{C-n})
384 Move `down' through the history list.
385
386 @item beginning-of-history (@key{M-<})
387 Move to the first line in the history.
388
389 @item end-of-history (@key{M->})
390 Move to the end of the input history, i.e., the line you are entering!
391
392 @item reverse-search-history (@key{C-r})
393 Search backward starting at the current line and moving `up' through
394 the history as necessary.  This is an incremental search.
395
396 @item forward-search-history (@key{C-s})
397 Search forward starting at the current line and moving `down' through
398 the the history as necessary.
399
400 @end ftable
401
402 @need 2000
403 @node Commands For Text
404 @subsubsection Commands For Changing Text
405
406 @ftable @code
407 @item delete-char (@key{C-d})
408 Delete the character under the cursor.  If the cursor is at the
409 beginning of the line, and there are no characters in the line, and
410 the last character typed was not @key{C-d}, then return EOF.
411
412 @item backward-delete-char (Rubout)
413 Delete the character behind the cursor.  A numeric arg says to kill
414 the characters instead of deleting them.
415
416 @item quoted-insert (@key{C-q}, @key{C-v})
417 Add the next character that you type to the line verbatim.  This is
418 how to insert things like @key{C-q} for example.
419
420 @item tab-insert (@key{M-TAB})
421 Insert a tab character.
422
423 @item self-insert (a, b, A, 1, !, ...)
424 Insert yourself.
425
426 @item transpose-chars (@key{C-t})
427 Drag the character before point forward over the character at point.
428 Point moves forward as well.  If point is at the end of the line, then
429 transpose the two characters before point.  Negative args don't work.
430
431 @item transpose-words (@key{M-t})
432 Drag the word behind the cursor past the word in front of the cursor
433 moving the cursor over that word as well.
434
435 @item upcase-word (@key{M-u})
436 Uppercase all letters in the current (or following) word.  With a
437 negative argument, do the previous word, but do not move point.
438
439 @item downcase-word (@key{M-l})
440 Lowercase all letters in the current (or following) word.  With a
441 negative argument, do the previous word, but do not move point.
442
443 @item capitalize-word (@key{M-c})
444 Uppercase the first letter in the current (or following) word.  With a
445 negative argument, do the previous word, but do not move point.
446
447 @end ftable
448
449 @need 2000
450 @node Commands For Killing
451 @subsubsection Killing And Yanking
452
453 @ftable @code
454 @item kill-line (@key{C-k})
455 Kill the text from the current cursor position to the end of the line.
456
457 @item backward-kill-line ()
458 Kill backward to the beginning of the line.  This is normally unbound.
459
460 @item kill-word (@key{M-d})
461 Kill from the cursor to the end of the current word, or if between
462 words, to the end of the next word.
463
464 @item backward-kill-word (@key{M-DEL})
465 Kill the word behind the cursor.
466
467 @item unix-line-discard (@key{C-u})
468 Do what @key{C-u} used to do in Unix line input.  We save the killed text on
469 the kill-ring, though.
470
471 @item unix-word-rubout (@key{C-w})
472 Do what @key{C-w} used to do in Unix line input.  The killed text is saved
473 on the kill-ring.  This is different than backward-kill-word because
474 the word boundaries differ.
475
476 @item yank (@key{C-y})
477 Yank the top of the kill ring into the buffer at point.
478
479 @item yank-pop (@key{M-y})
480 Rotate the kill-ring, and yank the new top.  You can only do this if
481 the prior command is yank or yank-pop.
482 @end ftable
483
484 @need 2000
485 @node Numeric Arguments
486 @subsubsection Specifying Numeric Arguments
487
488 @ftable @code
489
490 @item digit-argument (@key{M-0}, @key{M-1}, ... @key{M--})
491 Add this digit to the argument already accumulating, or start a new
492 argument.  @key{M--} starts a negative argument.
493
494 @item universal-argument ()
495 Do what @key{C-u} does in emacs.  By default, this is not bound.
496 @end ftable
497
498
499 @need 2000
500 @node Commands For Completion
501 @subsubsection Letting Readline Type For You
502
503 @ftable @code
504 @item complete (TAB)
505 Attempt to do completion on the text before point.  This is
506 implementation defined.  Generally, if you are typing a filename
507 argument, you can do filename completion; if you are typing a command,
508 you can do command completion, if you are typing in a symbol to GDB, you
509 can do symbol name completion, if you are typing in a variable to Bash,
510 you can do variable name completion...
511
512 @item possible-completions (M-?)
513 List the possible completions of the text before point.
514 @end ftable
515
516 @need 2000
517 @node Miscellaneous Commands
518 @subsubsection Some Miscellaneous Commands
519
520 @ftable @code
521
522 @item re-read-init-file (@key{C-x} @key{C-r})
523 Read in the contents of your @file{~/.inputrc} file, and incorporate
524 any bindings found there.
525
526 @item abort (@key{C-g})
527 Stop running the current editing command.
528
529 @ignore
530 @c I have no idea what this means, and can't figure it out by
531 @c experiment, and can't find it in the readline source.
532 @c pesch@cygnus.com, 20may1993.
533 @item do-uppercase-version (@key{M-a}, @key{M-b}, ...)
534 Run the command that is bound to your uppercase brother.
535 @end ignore
536
537 @item prefix-meta (ESC)
538 Make the next character that you type be metafied.  This is for people
539 without a meta key.  Typing @key{ESC f} is equivalent to typing
540 @key{M-f}.
541
542 @item undo (@key{C-_})
543 Incremental undo, separately remembered for each line.
544
545 @item revert-line (@key{M-r})
546 Undo all changes made to this line.  This is like typing the `undo'
547 command enough times to get back to the beginning.
548 @end ftable
549
550 @need 2000
551 @node Readline Vi Mode
552 @subsection Readline Vi Mode
553
554 @cindex @code{vi} style command editing
555 @kindex toggle-editing-mode
556 While the Readline library does not have a full set of Vi editing
557 functions, it does contain enough to allow simple editing of the line.
558
559 In order to switch interactively between Emacs and Vi editing modes, use
560 the command @key{M-C-j} (toggle-editing-mode).
561
562 When you enter a line in Vi mode, you are already placed in `insertion'
563 mode, as if you had typed an `i'.  Pressing @key{ESC} switches you into
564 `edit' mode, where you can edit the text of the line with the standard
565 Vi movement keys, move to previous history lines with `k', and following
566 lines with `j', and so forth.
567