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