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.)
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
13 Copyright (C) 1988-1999 Free Software Foundation, Inc.
15 Authored by Brian Fox and Chet Ramey.
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).
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
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.
32 Permission is granted to copy and distribute translations of this manual
33 into another language, under the above conditions for modified versions.
36 @comment If you are including this manual as an appendix, then set the
37 @comment variable readline-appendix.
43 @node Command Line Editing
44 @chapter Command Line Editing
46 This chapter describes the basic features of the @sc{gnu}
47 command line editing interface.
49 Command line editing is provided by the Readline library, which is
50 used by several different programs, including Bash.
54 * Introduction and Notation:: Notation used in this text.
55 * Readline Interaction:: The minimum set of commands for editing a line.
56 * Readline Init File:: Customizing Readline from a user's view.
57 * Bindable Readline Commands:: A description of most of the Readline commands
59 * Readline vi Mode:: A short description of how to make Readline
60 behave like the vi editor.
62 * Programmable Completion:: How to specify the possible completions for
64 * Programmable Completion Builtins:: Builtin commands to specify how to
65 complete arguments for a particular command.
69 @node Introduction and Notation
70 @section Introduction to Line Editing
72 The following paragraphs describe the notation used to represent
75 The text @key{C-k} is read as `Control-K' and describes the character
76 produced when the @key{k} key is pressed while the Control key
79 The text @key{M-k} is read as `Meta-K' and describes the character
80 produced when the Meta key (if you have one) is depressed, and the @key{k}
82 The Meta key is labeled @key{ALT} on many keyboards.
83 On keyboards with two keys labeled @key{ALT} (usually to either side of
84 the space bar), the @key{ALT} on the left side is generally set to
86 The @key{ALT} key on the right may also be configured to work as a
87 Meta key or may be configured as some other modifier, such as a
88 Compose key for typing accented characters.
90 If you do not have a Meta or @key{ALT} key, or another key working as
91 a Meta key, the identical keystroke can be generated by typing @key{ESC}
92 @i{first}, and then typing @key{k}.
93 Either process is known as @dfn{metafying} the @key{k} key.
95 The text @key{M-C-k} is read as `Meta-Control-k' and describes the
96 character produced by @dfn{metafying} @key{C-k}.
98 In addition, several keys have their own names. Specifically,
99 @key{DEL}, @key{ESC}, @key{LFD}, @key{SPC}, @key{RET}, and @key{TAB} all
100 stand for themselves when seen in this text, or in an init file
101 (@pxref{Readline Init File}).
102 If your keyboard lacks a @key{LFD} key, typing @key{C-j} will
103 produce the desired character.
104 The @key{RET} key may be labeled @key{Return} or @key{Enter} on
107 @node Readline Interaction
108 @section Readline Interaction
109 @cindex interaction, readline
111 Often during an interactive session you type in a long line of text,
112 only to notice that the first word on the line is misspelled. The
113 Readline library gives you a set of commands for manipulating the text
114 as you type it in, allowing you to just fix your typo, and not forcing
115 you to retype the majority of the line. Using these editing commands,
116 you move the cursor to the place that needs correction, and delete or
117 insert the text of the corrections. Then, when you are satisfied with
118 the line, you simply press @key{RETURN}. You do not have to be at the
119 end of the line to press @key{RETURN}; the entire line is accepted
120 regardless of the location of the cursor within the line.
123 * Readline Bare Essentials:: The least you need to know about Readline.
124 * Readline Movement Commands:: Moving about the input line.
125 * Readline Killing Commands:: How to delete text, and how to get it back!
126 * Readline Arguments:: Giving numeric arguments to commands.
127 * Searching:: Searching through previous lines.
130 @node Readline Bare Essentials
131 @subsection Readline Bare Essentials
132 @cindex notation, readline
133 @cindex command editing
134 @cindex editing command lines
136 In order to enter characters into the line, simply type them. The typed
137 character appears where the cursor was, and then the cursor moves one
138 space to the right. If you mistype a character, you can use your
139 erase character to back up and delete the mistyped character.
141 Sometimes you may mistype a character, and
142 not notice the error until you have typed several other characters. In
143 that case, you can type @key{C-b} to move the cursor to the left, and then
144 correct your mistake. Afterwards, you can move the cursor to the right
147 When you add text in the middle of a line, you will notice that characters
148 to the right of the cursor are `pushed over' to make room for the text
149 that you have inserted. Likewise, when you delete text behind the cursor,
150 characters to the right of the cursor are `pulled back' to fill in the
151 blank space created by the removal of the text. A list of the bare
152 essentials for editing the text of an input line follows.
156 Move back one character.
158 Move forward one character.
159 @item @key{DEL} or @key{Backspace}
160 Delete the character to the left of the cursor.
162 Delete the character underneath the cursor.
163 @item @w{Printing characters}
164 Insert the character into the line at the cursor.
165 @item @key{C-_} or @key{C-x C-u}
166 Undo the last editing command. You can undo all the way back to an
171 (Depending on your configuration, the @key{Backspace} key be set to
172 delete the character to the left of the cursor and the @key{DEL} key set
173 to delete the character underneath the cursor, like @key{C-d}, rather
174 than the character to the left of the cursor.)
176 @node Readline Movement Commands
177 @subsection Readline Movement Commands
180 The above table describes the most basic keystrokes that you need
181 in order to do editing of the input line. For your convenience, many
182 other commands have been added in addition to @key{C-b}, @key{C-f},
183 @key{C-d}, and @key{DEL}. Here are some commands for moving more rapidly
188 Move to the start of the line.
190 Move to the end of the line.
192 Move forward a word, where a word is composed of letters and digits.
194 Move backward a word.
196 Clear the screen, reprinting the current line at the top.
199 Notice how @key{C-f} moves forward a character, while @key{M-f} moves
200 forward a word. It is a loose convention that control keystrokes
201 operate on characters while meta keystrokes operate on words.
203 @node Readline Killing Commands
204 @subsection Readline Killing Commands
209 @dfn{Killing} text means to delete the text from the line, but to save
210 it away for later use, usually by @dfn{yanking} (re-inserting)
211 it back into the line.
212 (`Cut' and `paste' are more recent jargon for `kill' and `yank'.)
214 If the description for a command says that it `kills' text, then you can
215 be sure that you can get the text back in a different (or the same)
218 When you use a kill command, the text is saved in a @dfn{kill-ring}.
219 Any number of consecutive kills save all of the killed text together, so
220 that when you yank it back, you get it all. The kill
221 ring is not line specific; the text that you killed on a previously
222 typed line is available to be yanked back later, when you are typing
226 Here is the list of commands for killing text.
230 Kill the text from the current cursor position to the end of the line.
233 Kill from the cursor to the end of the current word, or, if between
234 words, to the end of the next word.
235 Word boundaries are the same as those used by @key{M-f}.
238 Kill from the cursor the start of the previous word, or, if between
239 words, to the start of the previous word.
240 Word boundaries are the same as those used by @key{M-b}.
243 Kill from the cursor to the previous whitespace. This is different than
244 @key{M-DEL} because the word boundaries differ.
248 Here is how to @dfn{yank} the text back into the line. Yanking
249 means to copy the most-recently-killed text from the kill buffer.
253 Yank the most recently killed text back into the buffer at the cursor.
256 Rotate the kill-ring, and yank the new top. You can only do this if
257 the prior command is @key{C-y} or @key{M-y}.
260 @node Readline Arguments
261 @subsection Readline Arguments
263 You can pass numeric arguments to Readline commands. Sometimes the
264 argument acts as a repeat count, other times it is the @i{sign} of the
265 argument that is significant. If you pass a negative argument to a
266 command which normally acts in a forward direction, that command will
267 act in a backward direction. For example, to kill text back to the
268 start of the line, you might type @samp{M-- C-k}.
270 The general way to pass numeric arguments to a command is to type meta
271 digits before the command. If the first `digit' typed is a minus
272 sign (@samp{-}), then the sign of the argument will be negative. Once
273 you have typed one meta digit to get the argument started, you can type
274 the remainder of the digits, and then the command. For example, to give
275 the @key{C-d} command an argument of 10, you could type @samp{M-1 0 C-d}.
278 @subsection Searching for Commands in the History
280 Readline provides commands for searching through the command history
282 (@pxref{Bash History Facilities})
284 for lines containing a specified string.
285 There are two search modes: @var{incremental} and @var{non-incremental}.
287 Incremental searches begin before the user has finished typing the
289 As each character of the search string is typed, Readline displays
290 the next entry from the history matching the string typed so far.
291 An incremental search requires only as many characters as needed to
292 find the desired history entry.
293 To search backward in the history for a particular string, type
294 @key{C-r}. Typing @key{C-s} searches forward through the history.
295 The characters present in the value of the @code{isearch-terminators} variable
296 are used to terminate an incremental search.
297 If that variable has not been assigned a value, the @key{ESC} and
298 @key{C-J} characters will terminate an incremental search.
299 @key{C-g} will abort an incremental search and restore the original line.
300 When the search is terminated, the history entry containing the
301 search string becomes the current line.
303 To find other matching entries in the history list, type @key{C-r} or
304 @key{C-s} as appropriate.
305 This will search backward or forward in the history for the next
306 entry matching the search string typed so far.
307 Any other key sequence bound to a Readline command will terminate
308 the search and execute that command.
309 For instance, a @key{RET} will terminate the search and accept
310 the line, thereby executing the command from the history list.
312 Non-incremental searches read the entire search string before starting
313 to search for matching history lines. The search string may be
314 typed by the user or be part of the contents of the current line.
316 @node Readline Init File
317 @section Readline Init File
318 @cindex initialization file, readline
320 Although the Readline library comes with a set of Emacs-like
321 keybindings installed by default, it is possible to use a different set
323 Any user can customize programs that use Readline by putting
324 commands in an @dfn{inputrc} file, conventionally in his home directory.
327 file is taken from the value of the shell variable @code{INPUTRC}. If
329 @ifclear BashFeatures
330 file is taken from the value of the environment variable @code{INPUTRC}. If
332 that variable is unset, the default is @file{~/.inputrc}.
334 When a program which uses the Readline library starts up, the
335 init file is read, and the key bindings are set.
337 In addition, the @code{C-x C-r} command re-reads this init file, thus
338 incorporating any changes that you might have made to it.
341 * Readline Init File Syntax:: Syntax for the commands in the inputrc file.
343 * Conditional Init Constructs:: Conditional key bindings in the inputrc file.
345 * Sample Init File:: An example inputrc file.
348 @node Readline Init File Syntax
349 @subsection Readline Init File Syntax
351 There are only a few basic constructs allowed in the
352 Readline init file. Blank lines are ignored.
353 Lines beginning with a @samp{#} are comments.
354 Lines beginning with a @samp{$} indicate conditional
355 constructs (@pxref{Conditional Init Constructs}). Other lines
356 denote variable settings and key bindings.
359 @item Variable Settings
360 You can modify the run-time behavior of Readline by
361 altering the values of variables in Readline
362 using the @code{set} command within the init file. Here is how to
363 change from the default Emacs-like key binding to use
364 @code{vi} line editing commands:
371 The @w{@code{bind -V}} command lists the current Readline variable names
372 and values. @xref{Bash Builtins}.
375 A great deal of run-time behavior is changeable with the following
382 Controls what happens when Readline wants to ring the terminal bell.
383 If set to @samp{none}, Readline never rings the bell. If set to
384 @samp{visible}, Readline uses a visible bell if one is available.
385 If set to @samp{audible} (the default), Readline attempts to ring
389 @vindex comment-begin
390 The string to insert at the beginning of the line when the
391 @code{insert-comment} command is executed. The default value
394 @item completion-ignore-case
395 If set to @samp{on}, Readline performs filename matching and completion
396 in a case-insensitive fashion.
397 The default value is @samp{off}.
399 @item completion-query-items
400 @vindex completion-query-items
401 The number of possible completions that determines when the user is
402 asked whether he wants to see the list of possibilities. If the
403 number of possible completions is greater than this value,
404 Readline will ask the user whether or not he wishes to view
405 them; otherwise, they are simply listed. The default limit is
410 If set to @samp{on}, Readline will convert characters with the
411 eighth bit set to an ASCII key sequence by stripping the eighth
412 bit and prefixing an @key{ESC} character, converting them to a
413 meta-prefixed key sequence. The default value is @samp{on}.
415 @item disable-completion
416 @vindex disable-completion
417 If set to @samp{On}, Readline will inhibit word completion.
418 Completion characters will be inserted into the line as if they had
419 been mapped to @code{self-insert}. The default is @samp{off}.
423 The @code{editing-mode} variable controls which default set of
424 key bindings is used. By default, Readline starts up in Emacs editing
425 mode, where the keystrokes are most similar to Emacs. This variable can be
426 set to either @samp{emacs} or @samp{vi}.
429 @vindex enable-keypad
430 When set to @samp{on}, Readline will try to enable the application
431 keypad when it is called. Some systems need this to enable the
432 arrow keys. The default is @samp{off}.
436 If set to @samp{on}, tilde expansion is performed when Readline
437 attempts word completion. The default is @samp{off}.
439 @item horizontal-scroll-mode
440 @vindex horizontal-scroll-mode
441 This variable can be set to either @samp{on} or @samp{off}. Setting it
442 to @samp{on} means that the text of the lines being edited will scroll
443 horizontally on a single screen line when they are longer than the width
444 of the screen, instead of wrapping onto a new screen line. By default,
445 this variable is set to @samp{off}.
450 If set to @samp{on}, Readline will enable eight-bit input (it
451 will not strip the eighth bit from the characters it reads),
452 regardless of what the terminal claims it can support. The
453 default value is @samp{off}. The name @code{meta-flag} is a
454 synonym for this variable.
456 @item isearch-terminators
457 @vindex isearch-terminators
458 The string of characters that should terminate an incremental search without
459 subsequently executing the character as a command (@pxref{Searching}).
460 If this variable has not been given a value, the characters @key{ESC} and
461 @key{C-J} will terminate an incremental search.
465 Sets Readline's idea of the current keymap for key binding commands.
466 Acceptable @code{keymap} names are
468 @code{emacs-standard},
472 @code{vi-command}, and
474 @code{vi} is equivalent to @code{vi-command}; @code{emacs} is
475 equivalent to @code{emacs-standard}. The default value is @code{emacs}.
476 The value of the @code{editing-mode} variable also affects the
479 @item mark-directories
480 If set to @samp{on}, completed directory names have a slash
481 appended. The default is @samp{on}.
483 @item mark-modified-lines
484 @vindex mark-modified-lines
485 This variable, when set to @samp{on}, causes Readline to display an
486 asterisk (@samp{*}) at the start of history lines which have been modified.
487 This variable is @samp{off} by default.
491 If set to @samp{on}, Readline will display characters with the
492 eighth bit set directly rather than as a meta-prefixed escape
493 sequence. The default is @samp{off}.
495 @item print-completions-horizontally
496 If set to @samp{on}, Readline will display completions with matches
497 sorted horizontally in alphabetical order, rather than down the screen.
498 The default is @samp{off}.
500 @item show-all-if-ambiguous
501 @vindex show-all-if-ambiguous
502 This alters the default behavior of the completion functions. If
504 words which have more than one possible completion cause the
505 matches to be listed immediately instead of ringing the bell.
506 The default value is @samp{off}.
509 @vindex visible-stats
510 If set to @samp{on}, a character denoting a file's type
511 is appended to the filename when listing possible
512 completions. The default is @samp{off}.
517 The syntax for controlling key bindings in the init file is
518 simple. First you need to find the name of the command that you
519 want to change. The following sections contain tables of the command
520 name, the default keybinding, if any, and a short description of what
523 Once you know the name of the command, simply place the name of the key
524 you wish to bind the command to, a colon, and then the name of the
525 command on a line in the init file. The name of the key
526 can be expressed in different ways, depending on which is most
530 The @w{@code{bind -p}} command displays Readline function names and
531 bindings in a format that can put directly into an initialization file.
532 @xref{Bash Builtins}.
536 @item @w{@var{keyname}: @var{function-name} or @var{macro}}
537 @var{keyname} is the name of a key spelled out in English. For example:
539 Control-u: universal-argument
540 Meta-Rubout: backward-kill-word
541 Control-o: "> output"
544 In the above example, @key{C-u} is bound to the function
545 @code{universal-argument}, and @key{C-o} is bound to run the macro
546 expressed on the right hand side (that is, to insert the text
547 @samp{> output} into the line).
549 @item @w{"@var{keyseq}": @var{function-name} or @var{macro}}
550 @var{keyseq} differs from @var{keyname} above in that strings
551 denoting an entire key sequence can be specified, by placing
552 the key sequence in double quotes. Some @sc{gnu} Emacs style key
553 escapes can be used, as in the following example, but the
554 special character names are not recognized.
557 "\C-u": universal-argument
558 "\C-x\C-r": re-read-init-file
559 "\e[11~": "Function Key 1"
562 In the above example, @key{C-u} is bound to the function
563 @code{universal-argument} (just as it was in the first example),
564 @samp{@key{C-x} @key{C-r}} is bound to the function @code{re-read-init-file},
565 and @samp{@key{ESC} @key{[} @key{1} @key{1} @key{~}} is bound to insert
566 the text @samp{Function Key 1}.
570 The following @sc{gnu} Emacs style escape sequences are available when
571 specifying key sequences:
583 @key{"}, a double quotation mark
585 @key{'}, a single quote or apostrophe
588 In addition to the @sc{gnu} Emacs style escape sequences, a second
589 set of backslash escapes is available:
609 the character whose @code{ASCII} code is the octal value @var{nnn}
610 (one to three digits)
612 the character whose @code{ASCII} code is the hexadecimal value @var{nnn}
613 (one to three digits)
616 When entering the text of a macro, single or double quotes must
617 be used to indicate a macro definition.
618 Unquoted text is assumed to be a function name.
619 In the macro body, the backslash escapes described above are expanded.
620 Backslash will quote any other character in the macro text,
621 including @samp{"} and @samp{'}.
622 For example, the following binding will make @samp{C-x \}
623 insert a single @samp{\} into the line:
630 @node Conditional Init Constructs
631 @subsection Conditional Init Constructs
633 Readline implements a facility similar in spirit to the conditional
634 compilation features of the C preprocessor which allows key
635 bindings and variable settings to be performed as the result
636 of tests. There are four parser directives used.
640 The @code{$if} construct allows bindings to be made based on the
641 editing mode, the terminal being used, or the application using
642 Readline. The text of the test extends to the end of the line;
643 no characters are required to isolate it.
647 The @code{mode=} form of the @code{$if} directive is used to test
648 whether Readline is in @code{emacs} or @code{vi} mode.
649 This may be used in conjunction
650 with the @samp{set keymap} command, for instance, to set bindings in
651 the @code{emacs-standard} and @code{emacs-ctlx} keymaps only if
652 Readline is starting out in @code{emacs} mode.
655 The @code{term=} form may be used to include terminal-specific
656 key bindings, perhaps to bind the key sequences output by the
657 terminal's function keys. The word on the right side of the
658 @samp{=} is tested against both the full name of the terminal and
659 the portion of the terminal name before the first @samp{-}. This
660 allows @code{sun} to match both @code{sun} and @code{sun-cmd},
664 The @var{application} construct is used to include
665 application-specific settings. Each program using the Readline
666 library sets the @var{application name}, and you can test for it.
667 This could be used to bind key sequences to functions useful for
668 a specific program. For instance, the following command adds a
669 key sequence that quotes the current or previous word in Bash:
672 # Quote the current or previous word
673 "\C-xq": "\eb\"\ef\""
679 This command, as seen in the previous example, terminates an
683 Commands in this branch of the @code{$if} directive are executed if
687 This directive takes a single filename as an argument and reads commands
688 and bindings from that file.
690 $include /etc/inputrc
694 @node Sample Init File
695 @subsection Sample Init File
697 Here is an example of an inputrc file. This illustrates key
698 binding, variable assignment, and conditional syntax.
702 # This file controls the behaviour of line input editing for
703 # programs that use the Gnu Readline library. Existing programs
704 # include FTP, Bash, and Gdb.
706 # You can re-read the inputrc file with C-x C-r.
707 # Lines beginning with '#' are comments.
709 # First, include any systemwide bindings and variable assignments from
711 $include /etc/Inputrc
714 # Set various bindings for emacs mode.
716 set editing-mode emacs
720 Meta-Control-h: backward-kill-word Text after the function name is ignored
723 # Arrow keys in keypad mode
725 #"\M-OD": backward-char
726 #"\M-OC": forward-char
727 #"\M-OA": previous-history
728 #"\M-OB": next-history
730 # Arrow keys in ANSI mode
732 "\M-[D": backward-char
733 "\M-[C": forward-char
734 "\M-[A": previous-history
735 "\M-[B": next-history
737 # Arrow keys in 8 bit keypad mode
739 #"\M-\C-OD": backward-char
740 #"\M-\C-OC": forward-char
741 #"\M-\C-OA": previous-history
742 #"\M-\C-OB": next-history
744 # Arrow keys in 8 bit ANSI mode
746 #"\M-\C-[D": backward-char
747 #"\M-\C-[C": forward-char
748 #"\M-\C-[A": previous-history
749 #"\M-\C-[B": next-history
755 # An old-style binding. This happens to be the default.
758 # Macros that are convenient for shell interaction
761 "\C-xp": "PATH=$@{PATH@}\e\C-e\C-a\ef\C-f"
762 # prepare to type a quoted word -- insert open and close double quotes
763 # and move to just after the open quote
765 # insert a backslash (testing backslash escapes in sequences and macros)
767 # Quote the current or previous word
768 "\C-xq": "\eb\"\ef\""
769 # Add a binding to refresh the line, which is unbound
770 "\C-xr": redraw-current-line
771 # Edit variable on current line.
772 "\M-\C-v": "\C-a\C-k$\C-y\M-\C-e\C-a\C-y="
775 # use a visible bell if one is available
776 set bell-style visible
778 # don't strip characters to 7 bits when reading
781 # allow iso-latin1 characters to be inserted rather than converted to
782 # prefix-meta sequences
785 # display characters with the eighth bit set directly rather than
786 # as meta-prefixed characters
789 # if there are more than 150 possible completions for a word, ask the
790 # user if he wants to see all of them
791 set completion-query-items 150
797 "\M-.": yank-last-arg
801 @node Bindable Readline Commands
802 @section Bindable Readline Commands
805 * Commands For Moving:: Moving about the line.
806 * Commands For History:: Getting at previous lines.
807 * Commands For Text:: Commands for changing text.
808 * Commands For Killing:: Commands for killing and yanking.
809 * Numeric Arguments:: Specifying numeric arguments, repeat counts.
810 * Commands For Completion:: Getting Readline to do the typing for you.
811 * Keyboard Macros:: Saving and re-executing typed characters
812 * Miscellaneous Commands:: Other miscellaneous commands.
815 This section describes Readline commands that may be bound to key
818 You can list your key bindings by executing
819 @w{@code{bind -P}} or, for a more terse format, suitable for an
820 @var{inputrc} file, @w{@code{bind -p}}. (@xref{Bash Builtins}.)
823 Command names without an accompanying key sequence are unbound by default.
824 In the following descriptions, @var{point} refers to the current cursor
825 position, and @var{mark} refers to a cursor position saved by the
826 @code{set-mark} command.
827 The text between the point and mark is referred to as the @var{region}.
829 @node Commands For Moving
830 @subsection Commands For Moving
832 @item beginning-of-line (C-a)
833 Move to the start of the current line.
835 @item end-of-line (C-e)
836 Move to the end of the line.
838 @item forward-char (C-f)
839 Move forward a character.
841 @item backward-char (C-b)
842 Move back a character.
844 @item forward-word (M-f)
845 Move forward to the end of the next word. Words are composed of
848 @item backward-word (M-b)
849 Move back to the start of the current or previous word. Words are
850 composed of letters and digits.
852 @item clear-screen (C-l)
853 Clear the screen and redraw the current line,
854 leaving the current line at the top of the screen.
856 @item redraw-current-line ()
857 Refresh the current line. By default, this is unbound.
861 @node Commands For History
862 @subsection Commands For Manipulating The History
865 @item accept-line (Newline, Return)
867 Accept the line regardless of where the cursor is. If this line is
868 non-empty, add it to the history list according to the setting of
869 the @code{HISTCONTROL} and @code{HISTIGNORE} variables.
870 If this line was a history line, then restore the history line to its
873 @ifclear BashFeatures
874 Accept the line regardless of where the cursor is. If this line is
875 non-empty, add it to the history list. If this line was a history
876 line, then restore the history line to its original state.
879 @item previous-history (C-p)
880 Move `up' through the history list.
882 @item next-history (C-n)
883 Move `down' through the history list.
885 @item beginning-of-history (M-<)
886 Move to the first line in the history.
888 @item end-of-history (M->)
889 Move to the end of the input history, i.e., the line currently
892 @item reverse-search-history (C-r)
893 Search backward starting at the current line and moving `up' through
894 the history as necessary. This is an incremental search.
896 @item forward-search-history (C-s)
897 Search forward starting at the current line and moving `down' through
898 the the history as necessary. This is an incremental search.
900 @item non-incremental-reverse-search-history (M-p)
901 Search backward starting at the current line and moving `up'
902 through the history as necessary using a non-incremental search
903 for a string supplied by the user.
905 @item non-incremental-forward-search-history (M-n)
906 Search forward starting at the current line and moving `down'
907 through the the history as necessary using a non-incremental search
908 for a string supplied by the user.
910 @item history-search-forward ()
911 Search forward through the history for the string of characters
912 between the start of the current line and the point.
913 This is a non-incremental search.
914 By default, this command is unbound.
916 @item history-search-backward ()
917 Search backward through the history for the string of characters
918 between the start of the current line and the point. This
919 is a non-incremental search. By default, this command is unbound.
921 @item yank-nth-arg (M-C-y)
922 Insert the first argument to the previous command (usually
923 the second word on the previous line). With an argument @var{n},
924 insert the @var{n}th word from the previous command (the words
925 in the previous command begin with word 0). A negative argument
926 inserts the @var{n}th word from the end of the previous command.
928 @item yank-last-arg (M-., M-_)
929 Insert last argument to the previous command (the last word of the
930 previous history entry). With an
931 argument, behave exactly like @code{yank-nth-arg}.
932 Successive calls to @code{yank-last-arg} move back through the history
933 list, inserting the last argument of each line in turn.
937 @node Commands For Text
938 @subsection Commands For Changing Text
941 @item delete-char (C-d)
942 Delete the character under the cursor. If the cursor is at the
943 beginning of the line, there are no characters in the line, and
944 the last character typed was not bound to @code{delete-char}, then
947 @item backward-delete-char (Rubout)
948 Delete the character behind the cursor. A numeric argument means
949 to kill the characters instead of deleting them.
951 @item forward-backward-delete-char ()
952 Delete the character under the cursor, unless the cursor is at the
953 end of the line, in which case the character behind the cursor is
954 deleted. By default, this is not bound to a key.
956 @item quoted-insert (C-q, C-v)
957 Add the next character typed to the line verbatim. This is
958 how to insert key sequences like @key{C-q}, for example.
960 @ifclear BashFeatures
961 @item tab-insert (M-TAB)
962 Insert a tab character.
965 @item self-insert (a, b, A, 1, !, ...)
968 @item transpose-chars (C-t)
969 Drag the character before the cursor forward over
970 the character at the cursor, moving the
971 cursor forward as well. If the insertion point
972 is at the end of the line, then this
973 transposes the last two characters of the line.
974 Negative arguments have no effect.
976 @item transpose-words (M-t)
977 Drag the word before point past the word after point,
978 moving point past that word as well.
980 @item upcase-word (M-u)
981 Uppercase the current (or following) word. With a negative argument,
982 uppercase the previous word, but do not move the cursor.
984 @item downcase-word (M-l)
985 Lowercase the current (or following) word. With a negative argument,
986 lowercase the previous word, but do not move the cursor.
988 @item capitalize-word (M-c)
989 Capitalize the current (or following) word. With a negative argument,
990 capitalize the previous word, but do not move the cursor.
994 @node Commands For Killing
995 @subsection Killing And Yanking
999 @item kill-line (C-k)
1000 Kill the text from point to the end of the line.
1002 @item backward-kill-line (C-x Rubout)
1003 Kill backward to the beginning of the line.
1005 @item unix-line-discard (C-u)
1006 Kill backward from the cursor to the beginning of the current line.
1008 @item kill-whole-line ()
1009 Kill all characters on the current line, no matter point is.
1010 By default, this is unbound.
1012 @item kill-word (M-d)
1013 Kill from point to the end of the current word, or if between
1014 words, to the end of the next word.
1015 Word boundaries are the same as @code{forward-word}.
1017 @item backward-kill-word (M-DEL)
1018 Kill the word behind point.
1019 Word boundaries are the same as @code{backward-word}.
1021 @item unix-word-rubout (C-w)
1022 Kill the word behind point, using white space as a word boundary.
1023 The killed text is saved on the kill-ring.
1025 @item delete-horizontal-space ()
1026 Delete all spaces and tabs around point. By default, this is unbound.
1028 @item kill-region ()
1029 Kill the text in the current region.
1030 By default, this command is unbound.
1032 @item copy-region-as-kill ()
1033 Copy the text in the region to the kill buffer, so it can be yanked
1034 right away. By default, this command is unbound.
1036 @item copy-backward-word ()
1037 Copy the word before point to the kill buffer.
1038 The word boundaries are the same as @code{backward-word}.
1039 By default, this command is unbound.
1041 @item copy-forward-word ()
1042 Copy the word following point to the kill buffer.
1043 The word boundaries are the same as @code{forward-word}.
1044 By default, this command is unbound.
1047 Yank the top of the kill ring into the buffer at the current
1050 @item yank-pop (M-y)
1051 Rotate the kill-ring, and yank the new top. You can only do this if
1052 the prior command is yank or yank-pop.
1055 @node Numeric Arguments
1056 @subsection Specifying Numeric Arguments
1059 @item digit-argument (M-0, M-1, ... M--)
1060 Add this digit to the argument already accumulating, or start a new
1061 argument. @key{M--} starts a negative argument.
1063 @item universal-argument ()
1064 This is another way to specify an argument.
1065 If this command is followed by one or more digits, optionally with a
1066 leading minus sign, those digits define the argument.
1067 If the command is followed by digits, executing @code{universal-argument}
1068 again ends the numeric argument, but is otherwise ignored.
1069 As a special case, if this command is immediately followed by a
1070 character that is neither a digit or minus sign, the argument count
1071 for the next command is multiplied by four.
1072 The argument count is initially one, so executing this function the
1073 first time makes the argument count four, a second time makes the
1074 argument count sixteen, and so on.
1075 By default, this is not bound to a key.
1078 @node Commands For Completion
1079 @subsection Letting Readline Type For You
1082 @item complete (TAB)
1083 Attempt to do completion on the text before the cursor. This is
1084 application-specific. Generally, if you are typing a filename
1085 argument, you can do filename completion; if you are typing a command,
1086 you can do command completion; if you are typing in a symbol to GDB, you
1087 can do symbol name completion; if you are typing in a variable to Bash,
1088 you can do variable name completion, and so on.
1090 Bash attempts completion treating the text as a variable (if the
1091 text begins with @samp{$}), username (if the text begins with
1092 @samp{~}), hostname (if the text begins with @samp{@@}), or
1093 command (including aliases and functions) in turn. If none
1094 of these produces a match, filename completion is attempted.
1097 @item possible-completions (M-?)
1098 List the possible completions of the text before the cursor.
1100 @item insert-completions (M-*)
1101 Insert all completions of the text before point that would have
1102 been generated by @code{possible-completions}.
1104 @item menu-complete ()
1105 Similar to @code{complete}, but replaces the word to be completed
1106 with a single match from the list of possible completions.
1107 Repeated execution of @code{menu-complete} steps through the list
1108 of possible completions, inserting each match in turn.
1109 At the end of the list of completions, the bell is rung and the
1110 original text is restored.
1111 An argument of @var{n} moves @var{n} positions forward in the list
1112 of matches; a negative argument may be used to move backward
1114 This command is intended to be bound to @code{TAB}, but is unbound
1117 @item delete-char-or-list ()
1118 Deletes the character under the cursor if not at the beginning or
1119 end of the line (like @code{delete-char}).
1120 If at the end of the line, behaves identically to
1121 @code{possible-completions}.
1122 This command is unbound by default.
1125 @item complete-filename (M-/)
1126 Attempt filename completion on the text before point.
1128 @item possible-filename-completions (C-x /)
1129 List the possible completions of the text before point,
1130 treating it as a filename.
1132 @item complete-username (M-~)
1133 Attempt completion on the text before point, treating
1136 @item possible-username-completions (C-x ~)
1137 List the possible completions of the text before point,
1138 treating it as a username.
1140 @item complete-variable (M-$)
1141 Attempt completion on the text before point, treating
1142 it as a shell variable.
1144 @item possible-variable-completions (C-x $)
1145 List the possible completions of the text before point,
1146 treating it as a shell variable.
1148 @item complete-hostname (M-@@)
1149 Attempt completion on the text before point, treating
1152 @item possible-hostname-completions (C-x @@)
1153 List the possible completions of the text before point,
1154 treating it as a hostname.
1156 @item complete-command (M-!)
1157 Attempt completion on the text before point, treating
1158 it as a command name. Command completion attempts to
1159 match the text against aliases, reserved words, shell
1160 functions, shell builtins, and finally executable filenames,
1163 @item possible-command-completions (C-x !)
1164 List the possible completions of the text before point,
1165 treating it as a command name.
1167 @item dynamic-complete-history (M-TAB)
1168 Attempt completion on the text before point, comparing
1169 the text against lines from the history list for possible
1172 @item complete-into-braces (M-@{)
1173 Perform filename completion and insert the list of possible completions
1174 enclosed within braces so the list is available to the shell
1175 (@pxref{Brace Expansion}).
1180 @node Keyboard Macros
1181 @subsection Keyboard Macros
1184 @item start-kbd-macro (C-x ()
1185 Begin saving the characters typed into the current keyboard macro.
1187 @item end-kbd-macro (C-x ))
1188 Stop saving the characters typed into the current keyboard macro
1189 and save the definition.
1191 @item call-last-kbd-macro (C-x e)
1192 Re-execute the last keyboard macro defined, by making the characters
1193 in the macro appear as if typed at the keyboard.
1197 @node Miscellaneous Commands
1198 @subsection Some Miscellaneous Commands
1201 @item re-read-init-file (C-x C-r)
1202 Read in the contents of the @var{inputrc} file, and incorporate
1203 any bindings or variable assignments found there.
1206 Abort the current editing command and
1207 ring the terminal's bell (subject to the setting of
1210 @item do-uppercase-version (M-a, M-b, M-@var{x}, @dots{})
1211 If the metafied character @var{x} is lowercase, run the command
1212 that is bound to the corresponding uppercase character.
1214 @item prefix-meta (ESC)
1215 Make the next character typed be metafied. This is for keyboards
1216 without a meta key. Typing @samp{ESC f} is equivalent to typing
1219 @item undo (C-_, C-x C-u)
1220 Incremental undo, separately remembered for each line.
1222 @item revert-line (M-r)
1223 Undo all changes made to this line. This is like executing the @code{undo}
1224 command enough times to get back to the beginning.
1227 @item tilde-expand (M-&)
1229 @ifclear BashFeatures
1230 @item tilde-expand (M-~)
1232 Perform tilde expansion on the current word.
1234 @item set-mark (C-@@)
1235 Set the mark to the current point. If a
1236 numeric argument is supplied, the mark is set to that position.
1238 @item exchange-point-and-mark (C-x C-x)
1239 Swap the point with the mark. The current cursor position is set to
1240 the saved position, and the old cursor position is saved as the mark.
1242 @item character-search (C-])
1243 A character is read and point is moved to the next occurrence of that
1244 character. A negative count searches for previous occurrences.
1246 @item character-search-backward (M-C-])
1247 A character is read and point is moved to the previous occurrence
1248 of that character. A negative count searches for subsequent
1251 @item insert-comment (M-#)
1252 The value of the @code{comment-begin}
1253 variable is inserted at the beginning of the current line,
1254 and the line is accepted as if a newline had been typed.
1256 The default value of @code{comment-begin} causes this command
1257 to make the current line a shell comment.
1260 @item dump-functions ()
1261 Print all of the functions and their key bindings to the
1262 Readline output stream. If a numeric argument is supplied,
1263 the output is formatted in such a way that it can be made part
1264 of an @var{inputrc} file. This command is unbound by default.
1266 @item dump-variables ()
1267 Print all of the settable variables and their values to the
1268 Readline output stream. If a numeric argument is supplied,
1269 the output is formatted in such a way that it can be made part
1270 of an @var{inputrc} file. This command is unbound by default.
1272 @item dump-macros ()
1273 Print all of the Readline key sequences bound to macros and the
1274 strings they ouput. If a numeric argument is supplied,
1275 the output is formatted in such a way that it can be made part
1276 of an @var{inputrc} file. This command is unbound by default.
1279 @item glob-expand-word (C-x *)
1280 The word before point is treated as a pattern for pathname expansion,
1281 and the list of matching file names is inserted, replacing the word.
1283 @item glob-list-expansions (C-x g)
1284 The list of expansions that would have been generated by
1285 @code{glob-expand-word} is displayed, and the line is redrawn.
1287 @item display-shell-version (C-x C-v)
1288 Display version information about the current instance of Bash.
1290 @item shell-expand-line (M-C-e)
1291 Expand the line as the shell does.
1292 This performs alias and history expansion as well as all of the shell
1293 word expansions (@pxref{Shell Expansions}).
1295 @item history-expand-line (M-^)
1296 Perform history expansion on the current line.
1298 @item magic-space ()
1299 Perform history expansion on the current line and insert a space
1300 (@pxref{History Interaction}).
1302 @item alias-expand-line ()
1303 Perform alias expansion on the current line (@pxref{Aliases}).
1305 @item history-and-alias-expand-line ()
1306 Perform history and alias expansion on the current line.
1308 @item insert-last-argument (M-., M-_)
1309 A synonym for @code{yank-last-arg}.
1311 @item operate-and-get-next (C-o)
1312 Accept the current line for execution and fetch the next line
1313 relative to the current line from the history for editing. Any
1314 argument is ignored.
1316 @item emacs-editing-mode (C-e)
1317 When in @code{vi} editing mode, this causes a switch back to
1318 @code{emacs} editing mode, as if the command @samp{set -o emacs} had
1325 @node Readline vi Mode
1326 @section Readline vi Mode
1328 While the Readline library does not have a full set of @code{vi}
1329 editing functions, it does contain enough to allow simple editing
1330 of the line. The Readline @code{vi} mode behaves as specified in
1331 the @sc{POSIX} 1003.2 standard.
1334 In order to switch interactively between @code{emacs} and @code{vi}
1335 editing modes, use the @samp{set -o emacs} and @samp{set -o vi}
1336 commands (@pxref{The Set Builtin}).
1338 @ifclear BashFeatures
1339 In order to switch interactively between @code{emacs} and @code{vi}
1340 editing modes, use the command M-C-j (toggle-editing-mode).
1342 The Readline default is @code{emacs} mode.
1344 When you enter a line in @code{vi} mode, you are already placed in
1345 `insertion' mode, as if you had typed an @samp{i}. Pressing @key{ESC}
1346 switches you into `command' mode, where you can edit the text of the
1347 line with the standard @code{vi} movement keys, move to previous
1348 history lines with @samp{k} and subsequent lines with @samp{j}, and
1352 @node Programmable Completion
1353 @section Programmable Completion
1354 @cindex programmable completion
1356 When word completion is attempted for an argument to a command for
1357 which a completion specification (a @var{compspec}) has been defined
1358 using the @code{complete} builtin (@pxref{Programmable Completion Builtins}),
1359 the programmable completion facilities are invoked.
1361 First, the command name is identified.
1362 If a compspec has been defined for that command, the
1363 compspec is used to generate the list of possible completions for the word.
1364 If the command word is a full pathname, a compspec for the full
1365 pathname is searched for first.
1366 If no compspec is found for the full pathname, an attempt is made to
1367 find a compspec for the portion following the final slash.
1369 Once a compspec has been found, it is used to generate the list of
1371 If a compspec is not found, the default Bash completion
1372 described above (@pxref{Commands For Completion}) is performed.
1374 First, the actions specified by the compspec are used.
1375 Only matches which are prefixed by the word being completed are
1377 When the @samp{-f} or @samp{-d} option is used for filename or
1378 directory name completion, the shell variable @code{FIGNORE} is
1379 used to filter the matches.
1380 @xref{Bash Variables}, for a description of @code{FIGNORE}.
1382 Any completions specified by a filename expansion pattern to the
1383 @samp{-G} option are generated next.
1384 The words generated by the pattern need not match the word being completed.
1385 The @code{GLOBIGNORE} shell variable is not used to filter the matches,
1386 but the @code{FIGNORE} shell variable is used.
1388 Next, the string specified as the argument to the @samp{-W} option
1390 The string is first split using the characters in the @code{IFS}
1391 special variable as delimiters.
1392 Shell quoting is honored.
1393 Each word is then expanded using
1394 brace expansion, tilde expansion, parameter and variable expansion,
1395 command substitution, arithmetic expansion, and pathname expansion,
1396 as described above (@pxref{Shell Expansions}).
1397 The results are split using the rules described above
1398 (@pxref{Word Splitting}).
1399 The results of the expansion are prefix-matched against the word being
1400 completed, and the matching words become the possible completions.
1402 After these matches have been generated, any shell function or command
1403 specified with the @samp{-F} and @samp{-C} options is invoked.
1404 When the command or function is invoked, the @code{COMP_LINE} and
1405 @code{COMP_POINT} variables are assigned values as described above
1406 (@pxref{Bash Variables}).
1407 If a shell function is being invoked, the @code{COMP_WORDS} and
1408 @code{COMP_CWORD} variables are also set.
1409 When the function or command is invoked, the first argument is the
1410 name of the command whose arguments are being completed, the
1411 second argument is the word being completed, and the third argument
1412 is the word preceding the word being completed on the current command line.
1413 No filtering of the generated completions against the word being completed
1414 is performed; the function or command has complete freedom in generating
1417 Any function specified with @samp{-F} is invoked first.
1418 The function may use any of the shell facilities, including the
1419 @code{compgen} builtin described below
1420 (@pxref{Programmable Completion Builtins}), to generate the matches.
1421 It must put the possible completions in the @code{COMPREPLY} array
1424 Next, any command specified with the @samp{-C} option is invoked
1425 in an environment equivalent to command substitution.
1426 It should print a list of completions, one per line, to
1427 the standard output.
1428 Backslash may be used to escape a newline, if necessary.
1430 After all of the possible completions are generated, any filter
1431 specified with the @samp{-X} option is applied to the list.
1432 The filter is a pattern as used for pathname expansion; a @samp{&}
1433 in the pattern is replaced with the text of the word being completed.
1434 A literal @samp{&} may be escaped with a backslash; the backslash
1435 is removed before attempting a match.
1436 Any completion that matches the pattern will be removed from the list.
1437 A leading @samp{!} negates the pattern; in this case any completion
1438 not matching the pattern will be removed.
1440 Finally, any prefix and suffix specified with the @samp{-P} and @samp{-S}
1441 options are added to each member of the completion list, and the result is
1442 returned to the Readline completion code as the list of possible
1445 If a compspec is found, whatever it generates is returned to the completion
1446 code as the full set of possible completions.
1447 The default Bash completions are not attempted, and the Readline
1448 default of filename completion is disabled.
1450 @node Programmable Completion Builtins
1451 @section Programmable Completion Builtins
1452 @cindex completion builtins
1454 Two builtin commands are available to manipulate the programmable completion
1461 @code{compgen [@var{option}] [@var{word}]}
1464 Generate possible completion matches for @var{word} according to
1465 the @var{option}s, which may be any option accepted by the
1467 builtin with the exception of @samp{-p} and @samp{-r}, and write
1468 the matches to the standard output.
1469 When using the @samp{-F} or @samp{-C} options, the various shell variables
1470 set by the programmable completion facilities, while available, will not
1473 The matches will be generated in the same way as if the programmable
1474 completion code had generated them directly from a completion specification
1475 with the same flags.
1476 If @var{word} is specified, only those completions matching @var{word}
1479 The return value is true unless an invalid option is supplied, or no
1480 matches were generated.
1485 @code{complete [-abcdefjkvu] [-A @var{action}] [-G @var{globpat}] [-W @var{wordlist}]
1486 [-P @var{prefix}] [-S @var{suffix}] [-X @var{filterpat}] [-F @var{function}]
1487 [-C @var{command}] @var{name} [@var{name} @dots{}]}
1488 @code{complete -pr [@var{name} @dots{}]}
1491 Specify how arguments to each @var{name} should be completed.
1492 If the @samp{-p} option is supplied, or if no options are supplied, existing
1493 completion specifications are printed in a way that allows them to be
1495 The @samp{-r} option removes a completion specification for
1496 each @var{name}, or, if no @var{name}s are supplied, all
1497 completion specifications.
1499 The process of applying these completion specifications when word completion
1500 is attempted is described above (@pxref{Programmable Completion}).
1502 Other options, if specified, have the following meanings.
1503 The arguments to the @samp{-G}, @samp{-W}, and @samp{-X} options
1504 (and, if necessary, the @samp{-P} and @samp{-S} options)
1505 should be quoted to protect them from expansion before the
1506 @code{complete} builtin is invoked.
1509 @item -A @var{action}
1510 The @var{action} may be one of the following to generate a list of possible
1515 Alias names. May also be specified as @samp{-a}.
1518 Array variable names.
1521 Readline key binding names (@pxref{Bindable Readline Commands}).
1524 Names of shell builtin commands. May also be specified as @samp{-b}.
1527 Command names. May also be specified as @samp{-c}.
1530 Directory names. May also be specified as @samp{-d}.
1533 Names of disabled shell builtins.
1536 Names of enabled shell builtins.
1539 Names of exported shell variables. May also be specified as @samp{-e}.
1542 File names. May also be specified as @samp{-f}.
1545 Names of shell functions.
1548 Help topics as accepted by the @code{help} builtin (@pxref{Bash Builtins}).
1551 Hostnames, as taken from the file specified by the
1552 @code{HOSTFILE} shell variable (@pxref{Bash Variables}).
1555 Job names, if job control is active. May also be specified as @samp{-j}.
1558 Shell reserved words. May also be specified as @samp{-k}.
1561 Names of running jobs, if job control is active.
1564 Valid arguments for the @samp{-o} option to the @code{set} builtin
1565 (@pxref{The Set Builtin}).
1568 Shell option names as accepted by the @code{shopt} builtin
1569 (@pxref{Bash Builtins}).
1575 Names of stopped jobs, if job control is active.
1578 User names. May also be specified as @samp{-u}.
1581 Names of all shell variables. May also be specified as @samp{-v}.
1584 @item -G @var{globpat}
1585 The filename expansion pattern @var{globpat} is expanded to generate
1586 the possible completions.
1588 @item -W @var{wordlist}
1589 The @var{wordlist} is split using the characters in the
1590 @code{IFS} special variable as delimiters, and each resultant word
1592 The possible completions are the members of the resultant list which
1593 match the word being completed.
1595 @item -C @var{command}
1596 @var{command} is executed in a subshell environment, and its output is
1597 used as the possible completions.
1599 @item -F @var{function}
1600 The shell function @var{function} is executed in the current shell
1602 When it finishes, the possible completions are retrieved from the value
1603 of the @code{COMPREPLY} array variable.
1605 @item -X @var{filterpat}
1606 @var{filterpat} is a pattern as used for filename expansion.
1607 It is applied to the list of possible completions generated by the
1608 preceding options and arguments, and each completion matching
1609 @var{filterpat} is removed from the list.
1610 A leading @samp{!} in @var{filterpat} negates the pattern; in this
1611 case, any completion not matching @var{filterpat} is removed.
1613 @item -P @var{prefix}
1614 @var{prefix} is added at the beginning of each possible completion
1615 after all other options have been applied.
1617 @item -S @var{suffix}
1618 @var{suffix} is appended to each possible completion
1619 after all other options have been applied.
1622 The return value is true unless an invalid option is supplied, an option
1623 other than @samp{-p} or @samp{-r} is supplied without a @var{name}
1624 argument, an attempt is made to remove a completion specification for
1625 a @var{name} for which no specification exists, or
1626 an error occurs adding a completion specification.