Commit | Line | Data |
---|---|---|
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 | |
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" | |
1b17e766 EZ |
10 | which contains both end-user and programmer documentation for the |
11 | GNU Readline Library. | |
d60d9f65 | 12 | |
1b17e766 | 13 | Copyright (C) 1988-1999 Free Software Foundation, Inc. |
d60d9f65 SS |
14 | |
15 | Authored by Brian Fox and Chet Ramey. | |
16 | ||
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). | |
21 | ||
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 | |
24 | all copies. | |
25 | ||
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. | |
31 | ||
32 | Permission is granted to copy and distribute translations of this manual | |
33 | into 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 | ||
1b17e766 EZ |
39 | @ifclear BashFeatures |
40 | @defcodeindex bt | |
41 | @end ifclear | |
42 | ||
d60d9f65 SS |
43 | @node Command Line Editing |
44 | @chapter Command Line Editing | |
45 | ||
1b17e766 | 46 | This chapter describes the basic features of the @sc{gnu} |
d60d9f65 | 47 | command line editing interface. |
1b17e766 EZ |
48 | @ifset BashFeatures |
49 | Command line editing is provided by the Readline library, which is | |
50 | used by several different programs, including Bash. | |
51 | @end ifset | |
d60d9f65 SS |
52 | |
53 | @menu | |
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 | |
58 | available for binding | |
59 | * Readline vi Mode:: A short description of how to make Readline | |
60 | behave like the vi editor. | |
1b17e766 EZ |
61 | @ifset BashFeatures |
62 | * Programmable Completion:: How to specify the possible completions for | |
63 | a specific command. | |
64 | * Programmable Completion Builtins:: Builtin commands to specify how to | |
65 | complete arguments for a particular command. | |
66 | @end ifset | |
d60d9f65 SS |
67 | @end menu |
68 | ||
69 | @node Introduction and Notation | |
70 | @section Introduction to Line Editing | |
71 | ||
72 | The following paragraphs describe the notation used to represent | |
73 | keystrokes. | |
74 | ||
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 | |
77 | is depressed. | |
78 | ||
79 | The text @key{M-k} is read as `Meta-K' and describes the character | |
1b17e766 EZ |
80 | produced when the Meta key (if you have one) is depressed, and the @key{k} |
81 | key is pressed. | |
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 | |
85 | work as a Meta key. | |
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. | |
89 | ||
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}. | |
d60d9f65 SS |
93 | Either process is known as @dfn{metafying} the @key{k} key. |
94 | ||
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}. | |
97 | ||
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}). | |
1b17e766 EZ |
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 | |
105 | some keyboards. | |
d60d9f65 SS |
106 | |
107 | @node Readline Interaction | |
108 | @section Readline Interaction | |
109 | @cindex interaction, readline | |
110 | ||
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. | |
121 | ||
122 | @menu | |
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. | |
c862e87b | 128 | @end menu |
d60d9f65 SS |
129 | |
130 | @node Readline Bare Essentials | |
131 | @subsection Readline Bare Essentials | |
132 | @cindex notation, readline | |
133 | @cindex command editing | |
134 | @cindex editing command lines | |
135 | ||
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. | |
140 | ||
1b17e766 EZ |
141 | Sometimes you may mistype a character, and |
142 | not notice the error until you have typed several other characters. In | |
d60d9f65 SS |
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 | |
145 | with @key{C-f}. | |
146 | ||
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 | |
1b17e766 | 151 | blank space created by the removal of the text. A list of the bare |
d60d9f65 SS |
152 | essentials for editing the text of an input line follows. |
153 | ||
154 | @table @asis | |
155 | @item @key{C-b} | |
156 | Move back one character. | |
157 | @item @key{C-f} | |
158 | Move forward one character. | |
1b17e766 | 159 | @item @key{DEL} or @key{Backspace} |
d60d9f65 SS |
160 | Delete the character to the left of the cursor. |
161 | @item @key{C-d} | |
162 | Delete the character underneath the cursor. | |
163 | @item @w{Printing characters} | |
164 | Insert the character into the line at the cursor. | |
1b17e766 | 165 | @item @key{C-_} or @key{C-x C-u} |
d60d9f65 SS |
166 | Undo the last editing command. You can undo all the way back to an |
167 | empty line. | |
168 | @end table | |
169 | ||
1b17e766 EZ |
170 | @noindent |
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.) | |
175 | ||
d60d9f65 SS |
176 | @node Readline Movement Commands |
177 | @subsection Readline Movement Commands | |
178 | ||
179 | ||
1b17e766 | 180 | The above table describes the most basic keystrokes that you need |
d60d9f65 SS |
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 | |
184 | about the line. | |
185 | ||
186 | @table @key | |
187 | @item C-a | |
188 | Move to the start of the line. | |
189 | @item C-e | |
190 | Move to the end of the line. | |
191 | @item M-f | |
192 | Move forward a word, where a word is composed of letters and digits. | |
193 | @item M-b | |
194 | Move backward a word. | |
195 | @item C-l | |
196 | Clear the screen, reprinting the current line at the top. | |
197 | @end table | |
198 | ||
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. | |
202 | ||
203 | @node Readline Killing Commands | |
204 | @subsection Readline Killing Commands | |
205 | ||
206 | @cindex killing text | |
207 | @cindex yanking text | |
208 | ||
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. | |
1b17e766 EZ |
212 | (`Cut' and `paste' are more recent jargon for `kill' and `yank'.) |
213 | ||
d60d9f65 SS |
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) | |
216 | place later. | |
217 | ||
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 | |
223 | another line. | |
224 | @cindex kill ring | |
225 | ||
226 | Here is the list of commands for killing text. | |
227 | ||
228 | @table @key | |
229 | @item C-k | |
230 | Kill the text from the current cursor position to the end of the line. | |
231 | ||
232 | @item M-d | |
1b17e766 | 233 | Kill from the cursor to the end of the current word, or, if between |
d60d9f65 | 234 | words, to the end of the next word. |
1b17e766 | 235 | Word boundaries are the same as those used by @key{M-f}. |
d60d9f65 SS |
236 | |
237 | @item M-DEL | |
1b17e766 | 238 | Kill from the cursor the start of the previous word, or, if between |
d60d9f65 | 239 | words, to the start of the previous word. |
1b17e766 | 240 | Word boundaries are the same as those used by @key{M-b}. |
d60d9f65 SS |
241 | |
242 | @item C-w | |
243 | Kill from the cursor to the previous whitespace. This is different than | |
244 | @key{M-DEL} because the word boundaries differ. | |
245 | ||
246 | @end table | |
247 | ||
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. | |
250 | ||
251 | @table @key | |
252 | @item C-y | |
253 | Yank the most recently killed text back into the buffer at the cursor. | |
254 | ||
255 | @item M-y | |
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}. | |
258 | @end table | |
259 | ||
260 | @node Readline Arguments | |
261 | @subsection Readline Arguments | |
262 | ||
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}. | |
269 | ||
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 | |
1b17e766 | 272 | sign (@samp{-}), then the sign of the argument will be negative. Once |
d60d9f65 SS |
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}. | |
276 | ||
277 | @node Searching | |
278 | @subsection Searching for Commands in the History | |
279 | ||
280 | Readline provides commands for searching through the command history | |
281 | @ifset BashFeatures | |
282 | (@pxref{Bash History Facilities}) | |
283 | @end ifset | |
284 | for lines containing a specified string. | |
285 | There are two search modes: @var{incremental} and @var{non-incremental}. | |
286 | ||
287 | Incremental searches begin before the user has finished typing the | |
288 | search string. | |
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. | |
1b17e766 EZ |
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 | |
c862e87b JM |
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. | |
d60d9f65 SS |
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. | |
1b17e766 EZ |
302 | |
303 | To find other matching entries in the history list, type @key{C-r} or | |
304 | @key{C-s} as appropriate. | |
d60d9f65 SS |
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. | |
311 | ||
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. | |
315 | ||
316 | @node Readline Init File | |
317 | @section Readline Init File | |
318 | @cindex initialization file, readline | |
319 | ||
1b17e766 | 320 | Although the Readline library comes with a set of Emacs-like |
d60d9f65 SS |
321 | keybindings installed by default, it is possible to use a different set |
322 | of keybindings. | |
323 | Any user can customize programs that use Readline by putting | |
1b17e766 | 324 | commands in an @dfn{inputrc} file, conventionally in his home directory. |
d60d9f65 SS |
325 | The name of this |
326 | @ifset BashFeatures | |
327 | file is taken from the value of the shell variable @code{INPUTRC}. If | |
328 | @end ifset | |
329 | @ifclear BashFeatures | |
330 | file is taken from the value of the environment variable @code{INPUTRC}. If | |
331 | @end ifclear | |
332 | that variable is unset, the default is @file{~/.inputrc}. | |
333 | ||
334 | When a program which uses the Readline library starts up, the | |
335 | init file is read, and the key bindings are set. | |
336 | ||
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. | |
339 | ||
340 | @menu | |
341 | * Readline Init File Syntax:: Syntax for the commands in the inputrc file. | |
342 | ||
343 | * Conditional Init Constructs:: Conditional key bindings in the inputrc file. | |
344 | ||
345 | * Sample Init File:: An example inputrc file. | |
346 | @end menu | |
347 | ||
348 | @node Readline Init File Syntax | |
349 | @subsection Readline Init File Syntax | |
350 | ||
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. | |
357 | ||
358 | @table @asis | |
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: | |
365 | ||
366 | @example | |
367 | set editing-mode vi | |
368 | @end example | |
369 | ||
1b17e766 EZ |
370 | @ifset BashFeatures |
371 | The @w{@code{bind -V}} command lists the current Readline variable names | |
372 | and values. @xref{Bash Builtins}. | |
373 | @end ifset | |
374 | ||
d60d9f65 SS |
375 | A great deal of run-time behavior is changeable with the following |
376 | variables. | |
377 | ||
378 | @table @code | |
379 | ||
380 | @item bell-style | |
381 | @vindex bell-style | |
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 | |
386 | the terminal's bell. | |
387 | ||
388 | @item comment-begin | |
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 | |
392 | is @code{"#"}. | |
393 | ||
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}. | |
398 | ||
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 | |
406 | @code{100}. | |
407 | ||
408 | @item convert-meta | |
409 | @vindex convert-meta | |
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 | |
1b17e766 | 412 | bit and prefixing an @key{ESC} character, converting them to a |
d60d9f65 SS |
413 | meta-prefixed key sequence. The default value is @samp{on}. |
414 | ||
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}. | |
420 | ||
421 | @item editing-mode | |
422 | @vindex editing-mode | |
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}. | |
427 | ||
428 | @item enable-keypad | |
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}. | |
433 | ||
434 | @item expand-tilde | |
435 | @vindex expand-tilde | |
436 | If set to @samp{on}, tilde expansion is performed when Readline | |
437 | attempts word completion. The default is @samp{off}. | |
438 | ||
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}. | |
446 | ||
c862e87b JM |
447 | @item input-meta |
448 | @vindex input-meta | |
449 | @vindex meta-flag | |
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. | |
455 | ||
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. | |
462 | ||
d60d9f65 SS |
463 | @item keymap |
464 | @vindex keymap | |
465 | Sets Readline's idea of the current keymap for key binding commands. | |
466 | Acceptable @code{keymap} names are | |
467 | @code{emacs}, | |
468 | @code{emacs-standard}, | |
469 | @code{emacs-meta}, | |
470 | @code{emacs-ctlx}, | |
471 | @code{vi}, | |
472 | @code{vi-command}, and | |
473 | @code{vi-insert}. | |
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 | |
477 | default keymap. | |
478 | ||
479 | @item mark-directories | |
480 | If set to @samp{on}, completed directory names have a slash | |
481 | appended. The default is @samp{on}. | |
482 | ||
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. | |
488 | ||
d60d9f65 SS |
489 | @item output-meta |
490 | @vindex output-meta | |
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}. | |
494 | ||
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}. | |
499 | ||
500 | @item show-all-if-ambiguous | |
501 | @vindex show-all-if-ambiguous | |
502 | This alters the default behavior of the completion functions. If | |
503 | set to @samp{on}, | |
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}. | |
507 | ||
508 | @item visible-stats | |
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}. | |
513 | ||
514 | @end table | |
515 | ||
516 | @item Key Bindings | |
517 | The syntax for controlling key bindings in the init file is | |
1b17e766 | 518 | simple. First you need to find the name of the command that you |
d60d9f65 SS |
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 | |
521 | the command does. | |
522 | ||
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 | |
527 | comfortable for you. | |
528 | ||
1b17e766 EZ |
529 | @ifset BashFeatures |
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}. | |
533 | @end ifset | |
534 | ||
d60d9f65 SS |
535 | @table @asis |
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: | |
538 | @example | |
539 | Control-u: universal-argument | |
540 | Meta-Rubout: backward-kill-word | |
541 | Control-o: "> output" | |
542 | @end example | |
543 | ||
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). | |
548 | ||
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 | |
1b17e766 | 552 | the key sequence in double quotes. Some @sc{gnu} Emacs style key |
d60d9f65 SS |
553 | escapes can be used, as in the following example, but the |
554 | special character names are not recognized. | |
555 | ||
556 | @example | |
557 | "\C-u": universal-argument | |
558 | "\C-x\C-r": re-read-init-file | |
559 | "\e[11~": "Function Key 1" | |
560 | @end example | |
561 | ||
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}. | |
567 | ||
568 | @end table | |
569 | ||
1b17e766 | 570 | The following @sc{gnu} Emacs style escape sequences are available when |
d60d9f65 SS |
571 | specifying key sequences: |
572 | ||
573 | @table @code | |
574 | @item @kbd{\C-} | |
575 | control prefix | |
576 | @item @kbd{\M-} | |
577 | meta prefix | |
578 | @item @kbd{\e} | |
579 | an escape character | |
580 | @item @kbd{\\} | |
581 | backslash | |
582 | @item @kbd{\"} | |
1b17e766 | 583 | @key{"}, a double quotation mark |
d60d9f65 | 584 | @item @kbd{\'} |
1b17e766 | 585 | @key{'}, a single quote or apostrophe |
d60d9f65 SS |
586 | @end table |
587 | ||
1b17e766 | 588 | In addition to the @sc{gnu} Emacs style escape sequences, a second |
d60d9f65 SS |
589 | set of backslash escapes is available: |
590 | ||
591 | @table @code | |
592 | @item \a | |
593 | alert (bell) | |
594 | @item \b | |
595 | backspace | |
596 | @item \d | |
597 | delete | |
598 | @item \f | |
599 | form feed | |
600 | @item \n | |
601 | newline | |
602 | @item \r | |
603 | carriage return | |
604 | @item \t | |
605 | horizontal tab | |
606 | @item \v | |
607 | vertical tab | |
608 | @item \@var{nnn} | |
1b17e766 | 609 | the character whose @code{ASCII} code is the octal value @var{nnn} |
d60d9f65 SS |
610 | (one to three digits) |
611 | @item \x@var{nnn} | |
1b17e766 | 612 | the character whose @code{ASCII} code is the hexadecimal value @var{nnn} |
d60d9f65 SS |
613 | (one to three digits) |
614 | @end table | |
615 | ||
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: | |
624 | @example | |
625 | "\C-x\\": "\\" | |
626 | @end example | |
627 | ||
628 | @end table | |
629 | ||
630 | @node Conditional Init Constructs | |
631 | @subsection Conditional Init Constructs | |
632 | ||
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. | |
637 | ||
638 | @table @code | |
639 | @item $if | |
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. | |
644 | ||
645 | @table @code | |
646 | @item mode | |
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. | |
653 | ||
654 | @item term | |
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}, | |
661 | for instance. | |
662 | ||
663 | @item application | |
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: | |
670 | @example | |
671 | $if Bash | |
672 | # Quote the current or previous word | |
673 | "\C-xq": "\eb\"\ef\"" | |
674 | $endif | |
675 | @end example | |
676 | @end table | |
677 | ||
678 | @item $endif | |
679 | This command, as seen in the previous example, terminates an | |
680 | @code{$if} command. | |
681 | ||
682 | @item $else | |
683 | Commands in this branch of the @code{$if} directive are executed if | |
684 | the test fails. | |
685 | ||
686 | @item $include | |
687 | This directive takes a single filename as an argument and reads commands | |
688 | and bindings from that file. | |
689 | @example | |
690 | $include /etc/inputrc | |
691 | @end example | |
692 | @end table | |
693 | ||
694 | @node Sample Init File | |
695 | @subsection Sample Init File | |
696 | ||
697 | Here is an example of an inputrc file. This illustrates key | |
698 | binding, variable assignment, and conditional syntax. | |
699 | ||
700 | @example | |
701 | @page | |
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. | |
705 | # | |
706 | # You can re-read the inputrc file with C-x C-r. | |
707 | # Lines beginning with '#' are comments. | |
708 | # | |
709 | # First, include any systemwide bindings and variable assignments from | |
710 | # /etc/Inputrc | |
711 | $include /etc/Inputrc | |
712 | ||
713 | # | |
714 | # Set various bindings for emacs mode. | |
715 | ||
716 | set editing-mode emacs | |
717 | ||
718 | $if mode=emacs | |
719 | ||
720 | Meta-Control-h: backward-kill-word Text after the function name is ignored | |
721 | ||
722 | # | |
723 | # Arrow keys in keypad mode | |
724 | # | |
725 | #"\M-OD": backward-char | |
726 | #"\M-OC": forward-char | |
727 | #"\M-OA": previous-history | |
728 | #"\M-OB": next-history | |
729 | # | |
730 | # Arrow keys in ANSI mode | |
731 | # | |
732 | "\M-[D": backward-char | |
733 | "\M-[C": forward-char | |
734 | "\M-[A": previous-history | |
735 | "\M-[B": next-history | |
736 | # | |
737 | # Arrow keys in 8 bit keypad mode | |
738 | # | |
739 | #"\M-\C-OD": backward-char | |
740 | #"\M-\C-OC": forward-char | |
741 | #"\M-\C-OA": previous-history | |
742 | #"\M-\C-OB": next-history | |
743 | # | |
744 | # Arrow keys in 8 bit ANSI mode | |
745 | # | |
746 | #"\M-\C-[D": backward-char | |
747 | #"\M-\C-[C": forward-char | |
748 | #"\M-\C-[A": previous-history | |
749 | #"\M-\C-[B": next-history | |
750 | ||
751 | C-q: quoted-insert | |
752 | ||
753 | $endif | |
754 | ||
755 | # An old-style binding. This happens to be the default. | |
756 | TAB: complete | |
757 | ||
758 | # Macros that are convenient for shell interaction | |
759 | $if Bash | |
760 | # edit the path | |
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 | |
764 | "\C-x\"": "\"\"\C-b" | |
765 | # insert a backslash (testing backslash escapes in sequences and macros) | |
766 | "\C-x\\": "\\" | |
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=" | |
773 | $endif | |
774 | ||
775 | # use a visible bell if one is available | |
776 | set bell-style visible | |
777 | ||
778 | # don't strip characters to 7 bits when reading | |
779 | set input-meta on | |
780 | ||
781 | # allow iso-latin1 characters to be inserted rather than converted to | |
782 | # prefix-meta sequences | |
783 | set convert-meta off | |
784 | ||
785 | # display characters with the eighth bit set directly rather than | |
786 | # as meta-prefixed characters | |
787 | set output-meta on | |
788 | ||
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 | |
792 | ||
793 | # For FTP | |
794 | $if Ftp | |
795 | "\C-xg": "get \M-?" | |
796 | "\C-xt": "put \M-?" | |
797 | "\M-.": yank-last-arg | |
798 | $endif | |
799 | @end example | |
800 | ||
801 | @node Bindable Readline Commands | |
802 | @section Bindable Readline Commands | |
803 | ||
804 | @menu | |
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. | |
813 | @end menu | |
814 | ||
815 | This section describes Readline commands that may be bound to key | |
816 | sequences. | |
1b17e766 EZ |
817 | @ifset BashFeatures |
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}.) | |
821 | @end ifset | |
822 | ||
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}. | |
d60d9f65 SS |
828 | |
829 | @node Commands For Moving | |
830 | @subsection Commands For Moving | |
831 | @ftable @code | |
832 | @item beginning-of-line (C-a) | |
833 | Move to the start of the current line. | |
834 | ||
835 | @item end-of-line (C-e) | |
836 | Move to the end of the line. | |
837 | ||
838 | @item forward-char (C-f) | |
839 | Move forward a character. | |
840 | ||
841 | @item backward-char (C-b) | |
842 | Move back a character. | |
843 | ||
844 | @item forward-word (M-f) | |
845 | Move forward to the end of the next word. Words are composed of | |
846 | letters and digits. | |
847 | ||
848 | @item backward-word (M-b) | |
1b17e766 | 849 | Move back to the start of the current or previous word. Words are |
d60d9f65 SS |
850 | composed of letters and digits. |
851 | ||
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. | |
855 | ||
856 | @item redraw-current-line () | |
857 | Refresh the current line. By default, this is unbound. | |
858 | ||
859 | @end ftable | |
860 | ||
861 | @node Commands For History | |
862 | @subsection Commands For Manipulating The History | |
863 | ||
864 | @ftable @code | |
865 | @item accept-line (Newline, Return) | |
866 | @ifset BashFeatures | |
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 | |
871 | original state. | |
872 | @end ifset | |
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. | |
877 | @end ifclear | |
878 | ||
879 | @item previous-history (C-p) | |
880 | Move `up' through the history list. | |
881 | ||
882 | @item next-history (C-n) | |
883 | Move `down' through the history list. | |
884 | ||
885 | @item beginning-of-history (M-<) | |
886 | Move to the first line in the history. | |
887 | ||
888 | @item end-of-history (M->) | |
889 | Move to the end of the input history, i.e., the line currently | |
890 | being entered. | |
891 | ||
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. | |
895 | ||
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. | |
899 | ||
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. | |
904 | ||
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. | |
909 | ||
910 | @item history-search-forward () | |
911 | Search forward through the history for the string of characters | |
1b17e766 EZ |
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. | |
d60d9f65 SS |
915 | |
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. | |
920 | ||
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. | |
927 | ||
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. | |
934 | ||
935 | @end ftable | |
936 | ||
937 | @node Commands For Text | |
938 | @subsection Commands For Changing Text | |
939 | ||
940 | @ftable @code | |
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 | |
945 | return @code{EOF}. | |
946 | ||
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. | |
950 | ||
c862e87b JM |
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. | |
955 | ||
d60d9f65 SS |
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. | |
959 | ||
960 | @ifclear BashFeatures | |
961 | @item tab-insert (M-TAB) | |
962 | Insert a tab character. | |
963 | @end ifclear | |
964 | ||
965 | @item self-insert (a, b, A, 1, !, ...) | |
966 | Insert yourself. | |
967 | ||
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. | |
1b17e766 | 974 | Negative arguments have no effect. |
d60d9f65 SS |
975 | |
976 | @item transpose-words (M-t) | |
1b17e766 EZ |
977 | Drag the word before point past the word after point, |
978 | moving point past that word as well. | |
d60d9f65 SS |
979 | |
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. | |
983 | ||
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. | |
987 | ||
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. | |
991 | ||
992 | @end ftable | |
993 | ||
994 | @node Commands For Killing | |
995 | @subsection Killing And Yanking | |
996 | ||
997 | @ftable @code | |
998 | ||
999 | @item kill-line (C-k) | |
1b17e766 | 1000 | Kill the text from point to the end of the line. |
d60d9f65 SS |
1001 | |
1002 | @item backward-kill-line (C-x Rubout) | |
1003 | Kill backward to the beginning of the line. | |
1004 | ||
1005 | @item unix-line-discard (C-u) | |
1006 | Kill backward from the cursor to the beginning of the current line. | |
d60d9f65 SS |
1007 | |
1008 | @item kill-whole-line () | |
1b17e766 EZ |
1009 | Kill all characters on the current line, no matter point is. |
1010 | By default, this is unbound. | |
d60d9f65 SS |
1011 | |
1012 | @item kill-word (M-d) | |
1b17e766 EZ |
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}. | |
d60d9f65 SS |
1016 | |
1017 | @item backward-kill-word (M-DEL) | |
1b17e766 EZ |
1018 | Kill the word behind point. |
1019 | Word boundaries are the same as @code{backward-word}. | |
d60d9f65 SS |
1020 | |
1021 | @item unix-word-rubout (C-w) | |
1b17e766 EZ |
1022 | Kill the word behind point, using white space as a word boundary. |
1023 | The killed text is saved on the kill-ring. | |
d60d9f65 SS |
1024 | |
1025 | @item delete-horizontal-space () | |
1026 | Delete all spaces and tabs around point. By default, this is unbound. | |
1027 | ||
1028 | @item kill-region () | |
1b17e766 | 1029 | Kill the text in the current region. |
d60d9f65 SS |
1030 | By default, this command is unbound. |
1031 | ||
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. | |
1035 | ||
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. | |
1040 | ||
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. | |
1045 | ||
1046 | @item yank (C-y) | |
1047 | Yank the top of the kill ring into the buffer at the current | |
1048 | cursor position. | |
1049 | ||
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. | |
1053 | @end ftable | |
1054 | ||
1055 | @node Numeric Arguments | |
1056 | @subsection Specifying Numeric Arguments | |
1057 | @ftable @code | |
1058 | ||
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. | |
1062 | ||
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. | |
1076 | @end ftable | |
1077 | ||
1078 | @node Commands For Completion | |
1079 | @subsection Letting Readline Type For You | |
1080 | ||
1081 | @ftable @code | |
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. | |
1089 | @ifset BashFeatures | |
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. | |
1095 | @end ifset | |
1096 | ||
1097 | @item possible-completions (M-?) | |
1098 | List the possible completions of the text before the cursor. | |
1099 | ||
1100 | @item insert-completions (M-*) | |
1101 | Insert all completions of the text before point that would have | |
1102 | been generated by @code{possible-completions}. | |
1103 | ||
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 | |
1113 | through the list. | |
1114 | This command is intended to be bound to @code{TAB}, but is unbound | |
1115 | by default. | |
1116 | ||
c862e87b JM |
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. | |
1123 | ||
d60d9f65 SS |
1124 | @ifset BashFeatures |
1125 | @item complete-filename (M-/) | |
1126 | Attempt filename completion on the text before point. | |
1127 | ||
1128 | @item possible-filename-completions (C-x /) | |
1129 | List the possible completions of the text before point, | |
1130 | treating it as a filename. | |
1131 | ||
1132 | @item complete-username (M-~) | |
1133 | Attempt completion on the text before point, treating | |
1134 | it as a username. | |
1135 | ||
1136 | @item possible-username-completions (C-x ~) | |
1137 | List the possible completions of the text before point, | |
1138 | treating it as a username. | |
1139 | ||
1140 | @item complete-variable (M-$) | |
1141 | Attempt completion on the text before point, treating | |
1142 | it as a shell variable. | |
1143 | ||
1144 | @item possible-variable-completions (C-x $) | |
1145 | List the possible completions of the text before point, | |
1146 | treating it as a shell variable. | |
1147 | ||
1148 | @item complete-hostname (M-@@) | |
1149 | Attempt completion on the text before point, treating | |
1150 | it as a hostname. | |
1151 | ||
1152 | @item possible-hostname-completions (C-x @@) | |
1153 | List the possible completions of the text before point, | |
1154 | treating it as a hostname. | |
1155 | ||
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, | |
1161 | in that order. | |
1162 | ||
1163 | @item possible-command-completions (C-x !) | |
1164 | List the possible completions of the text before point, | |
1165 | treating it as a command name. | |
1166 | ||
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 | |
1170 | completion matches. | |
1171 | ||
1172 | @item complete-into-braces (M-@{) | |
1b17e766 | 1173 | Perform filename completion and insert the list of possible completions |
d60d9f65 SS |
1174 | enclosed within braces so the list is available to the shell |
1175 | (@pxref{Brace Expansion}). | |
1176 | ||
1177 | @end ifset | |
1178 | @end ftable | |
1179 | ||
1180 | @node Keyboard Macros | |
1181 | @subsection Keyboard Macros | |
1182 | @ftable @code | |
1183 | ||
1184 | @item start-kbd-macro (C-x () | |
1185 | Begin saving the characters typed into the current keyboard macro. | |
1186 | ||
1187 | @item end-kbd-macro (C-x )) | |
1188 | Stop saving the characters typed into the current keyboard macro | |
1189 | and save the definition. | |
1190 | ||
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. | |
1194 | ||
1195 | @end ftable | |
1196 | ||
1197 | @node Miscellaneous Commands | |
1198 | @subsection Some Miscellaneous Commands | |
1199 | @ftable @code | |
1200 | ||
1201 | @item re-read-init-file (C-x C-r) | |
1b17e766 | 1202 | Read in the contents of the @var{inputrc} file, and incorporate |
d60d9f65 SS |
1203 | any bindings or variable assignments found there. |
1204 | ||
1205 | @item abort (C-g) | |
1206 | Abort the current editing command and | |
1207 | ring the terminal's bell (subject to the setting of | |
1208 | @code{bell-style}). | |
1209 | ||
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. | |
1213 | ||
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 | |
1217 | @samp{M-f}. | |
1218 | ||
1219 | @item undo (C-_, C-x C-u) | |
1220 | Incremental undo, separately remembered for each line. | |
1221 | ||
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. | |
1225 | ||
c862e87b JM |
1226 | @ifset BashFeatures |
1227 | @item tilde-expand (M-&) | |
1228 | @end ifset | |
1229 | @ifclear BashFeatures | |
d60d9f65 | 1230 | @item tilde-expand (M-~) |
c862e87b | 1231 | @end ifclear |
d60d9f65 SS |
1232 | Perform tilde expansion on the current word. |
1233 | ||
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. | |
1237 | ||
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. | |
1241 | ||
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. | |
1245 | ||
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 | |
1249 | occurrences. | |
1250 | ||
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. | |
1255 | @ifset BashFeatures | |
1b17e766 EZ |
1256 | The default value of @code{comment-begin} causes this command |
1257 | to make the current line a shell comment. | |
d60d9f65 SS |
1258 | @end ifset |
1259 | ||
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. | |
1265 | ||
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. | |
1271 | ||
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. | |
1277 | ||
1278 | @ifset BashFeatures | |
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. | |
1282 | ||
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. | |
1286 | ||
1287 | @item display-shell-version (C-x C-v) | |
1288 | Display version information about the current instance of Bash. | |
1289 | ||
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}). | |
1294 | ||
1295 | @item history-expand-line (M-^) | |
1296 | Perform history expansion on the current line. | |
1297 | ||
1298 | @item magic-space () | |
1299 | Perform history expansion on the current line and insert a space | |
1300 | (@pxref{History Interaction}). | |
1301 | ||
1302 | @item alias-expand-line () | |
1303 | Perform alias expansion on the current line (@pxref{Aliases}). | |
1304 | ||
1305 | @item history-and-alias-expand-line () | |
1306 | Perform history and alias expansion on the current line. | |
1307 | ||
1308 | @item insert-last-argument (M-., M-_) | |
1309 | A synonym for @code{yank-last-arg}. | |
1310 | ||
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. | |
1315 | ||
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 | |
1319 | been executed. | |
1320 | ||
1321 | @end ifset | |
1322 | ||
1323 | @end ftable | |
1324 | ||
1325 | @node Readline vi Mode | |
1326 | @section Readline vi Mode | |
1327 | ||
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. | |
1332 | ||
1333 | @ifset BashFeatures | |
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}). | |
1337 | @end ifset | |
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). | |
1341 | @end ifclear | |
1342 | The Readline default is @code{emacs} mode. | |
1343 | ||
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 | |
1349 | so forth. | |
1b17e766 EZ |
1350 | |
1351 | @ifset BashFeatures | |
1352 | @node Programmable Completion | |
1353 | @section Programmable Completion | |
1354 | @cindex programmable completion | |
1355 | ||
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. | |
1360 | ||
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. | |
1368 | ||
1369 | Once a compspec has been found, it is used to generate the list of | |
1370 | matching words. | |
1371 | If a compspec is not found, the default Bash completion | |
1372 | described above (@pxref{Commands For Completion}) is performed. | |
1373 | ||
1374 | First, the actions specified by the compspec are used. | |
1375 | Only matches which are prefixed by the word being completed are | |
1376 | returned. | |
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}. | |
1381 | ||
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. | |
1387 | ||
1388 | Next, the string specified as the argument to the @samp{-W} option | |
1389 | is considered. | |
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. | |
1401 | ||
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 | |
1415 | the matches. | |
1416 | ||
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 | |
1422 | variable. | |
1423 | ||
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. | |
1429 | ||
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. | |
1439 | ||
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 | |
1443 | completions. | |
1444 | ||
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. | |
1449 | ||
1450 | @node Programmable Completion Builtins | |
1451 | @section Programmable Completion Builtins | |
1452 | @cindex completion builtins | |
1453 | ||
1454 | Two builtin commands are available to manipulate the programmable completion | |
1455 | facilities. | |
1456 | ||
1457 | @table @code | |
1458 | @item compgen | |
1459 | @btindex compgen | |
1460 | @example | |
1461 | @code{compgen [@var{option}] [@var{word}]} | |
1462 | @end example | |
1463 | ||
1464 | Generate possible completion matches for @var{word} according to | |
1465 | the @var{option}s, which may be any option accepted by the | |
1466 | @code{complete} | |
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 | |
1471 | have useful values. | |
1472 | ||
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} | |
1477 | will be displayed. | |
1478 | ||
1479 | The return value is true unless an invalid option is supplied, or no | |
1480 | matches were generated. | |
1481 | ||
1482 | @item complete | |
1483 | @btindex complete | |
1484 | @example | |
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{}]} | |
1489 | @end example | |
1490 | ||
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 | |
1494 | reused as input. | |
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. | |
1498 | ||
1499 | The process of applying these completion specifications when word completion | |
1500 | is attempted is described above (@pxref{Programmable Completion}). | |
1501 | ||
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. | |
1507 | ||
1508 | @table @code | |
1509 | @item -A @var{action} | |
1510 | The @var{action} may be one of the following to generate a list of possible | |
1511 | completions: | |
1512 | ||
1513 | @table @code | |
1514 | @item alias | |
1515 | Alias names. May also be specified as @samp{-a}. | |
1516 | ||
1517 | @item arrayvar | |
1518 | Array variable names. | |
1519 | ||
1520 | @item binding | |
1521 | Readline key binding names (@pxref{Bindable Readline Commands}). | |
1522 | ||
1523 | @item builtin | |
1524 | Names of shell builtin commands. May also be specified as @samp{-b}. | |
1525 | ||
1526 | @item command | |
1527 | Command names. May also be specified as @samp{-c}. | |
1528 | ||
1529 | @item directory | |
1530 | Directory names. May also be specified as @samp{-d}. | |
1531 | ||
1532 | @item disabled | |
1533 | Names of disabled shell builtins. | |
1534 | ||
1535 | @item enabled | |
1536 | Names of enabled shell builtins. | |
1537 | ||
1538 | @item export | |
1539 | Names of exported shell variables. May also be specified as @samp{-e}. | |
1540 | ||
1541 | @item file | |
1542 | File names. May also be specified as @samp{-f}. | |
1543 | ||
1544 | @item function | |
1545 | Names of shell functions. | |
1546 | ||
1547 | @item helptopic | |
1548 | Help topics as accepted by the @code{help} builtin (@pxref{Bash Builtins}). | |
1549 | ||
1550 | @item hostname | |
1551 | Hostnames, as taken from the file specified by the | |
1552 | @code{HOSTFILE} shell variable (@pxref{Bash Variables}). | |
1553 | ||
1554 | @item job | |
1555 | Job names, if job control is active. May also be specified as @samp{-j}. | |
1556 | ||
1557 | @item keyword | |
1558 | Shell reserved words. May also be specified as @samp{-k}. | |
1559 | ||
1560 | @item running | |
1561 | Names of running jobs, if job control is active. | |
1562 | ||
1563 | @item setopt | |
1564 | Valid arguments for the @samp{-o} option to the @code{set} builtin | |
1565 | (@pxref{The Set Builtin}). | |
1566 | ||
1567 | @item shopt | |
1568 | Shell option names as accepted by the @code{shopt} builtin | |
1569 | (@pxref{Bash Builtins}). | |
1570 | ||
1571 | @item signal | |
1572 | Signal names. | |
1573 | ||
1574 | @item stopped | |
1575 | Names of stopped jobs, if job control is active. | |
1576 | ||
1577 | @item user | |
1578 | User names. May also be specified as @samp{-u}. | |
1579 | ||
1580 | @item variable | |
1581 | Names of all shell variables. May also be specified as @samp{-v}. | |
1582 | @end table | |
1583 | ||
1584 | @item -G @var{globpat} | |
1585 | The filename expansion pattern @var{globpat} is expanded to generate | |
1586 | the possible completions. | |
1587 | ||
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 | |
1591 | is expanded. | |
1592 | The possible completions are the members of the resultant list which | |
1593 | match the word being completed. | |
1594 | ||
1595 | @item -C @var{command} | |
1596 | @var{command} is executed in a subshell environment, and its output is | |
1597 | used as the possible completions. | |
1598 | ||
1599 | @item -F @var{function} | |
1600 | The shell function @var{function} is executed in the current shell | |
1601 | environment. | |
1602 | When it finishes, the possible completions are retrieved from the value | |
1603 | of the @code{COMPREPLY} array variable. | |
1604 | ||
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. | |
1612 | ||
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. | |
1616 | ||
1617 | @item -S @var{suffix} | |
1618 | @var{suffix} is appended to each possible completion | |
1619 | after all other options have been applied. | |
1620 | @end table | |
1621 | ||
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. | |
1627 | ||
1628 | @end table | |
1629 | @end ifset |