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