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