rluser.texi 88 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390
  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. @ignore
  5. This file documents the end user interface to the GNU command line
  6. editing features. It is to be an appendix to manuals for programs which
  7. use these features. There is a document entitled "readline.texinfo"
  8. which contains both end-user and programmer documentation for the
  9. GNU Readline Library.
  10. Copyright (C) 1988--2016 Free Software Foundation, Inc.
  11. Authored by Brian Fox and Chet Ramey.
  12. Permission is granted to process this file through Tex and print the
  13. results, provided the printed document carries copying permission notice
  14. identical to this one except for the removal of this paragraph (this
  15. paragraph not being relevant to the printed manual).
  16. Permission is granted to make and distribute verbatim copies of this manual
  17. provided the copyright notice and this permission notice are preserved on
  18. all copies.
  19. Permission is granted to copy and distribute modified versions of this
  20. manual under the conditions for verbatim copying, provided also that the
  21. GNU Copyright statement is available to the distributee, and provided that
  22. the entire resulting derived work is distributed under the terms of a
  23. permission notice identical to this one.
  24. Permission is granted to copy and distribute translations of this manual
  25. into another language, under the above conditions for modified versions.
  26. @end ignore
  27. @comment If you are including this manual as an appendix, then set the
  28. @comment variable readline-appendix.
  29. @ifclear BashFeatures
  30. @defcodeindex bt
  31. @end ifclear
  32. @node Command Line Editing
  33. @chapter Command Line Editing
  34. This chapter describes the basic features of the @sc{gnu}
  35. command line editing interface.
  36. @ifset BashFeatures
  37. Command line editing is provided by the Readline library, which is
  38. used by several different programs, including Bash.
  39. Command line editing is enabled by default when using an interactive shell,
  40. unless the @option{--noediting} option is supplied at shell invocation.
  41. Line editing is also used when using the @option{-e} option to the
  42. @code{read} builtin command (@pxref{Bash Builtins}).
  43. By default, the line editing commands are similar to those of Emacs.
  44. A vi-style line editing interface is also available.
  45. Line editing can be enabled at any time using the @option{-o emacs} or
  46. @option{-o vi} options to the @code{set} builtin command
  47. (@pxref{The Set Builtin}), or disabled using the @option{+o emacs} or
  48. @option{+o vi} options to @code{set}.
  49. @end ifset
  50. @menu
  51. * Introduction and Notation:: Notation used in this text.
  52. * Readline Interaction:: The minimum set of commands for editing a line.
  53. * Readline Init File:: Customizing Readline from a user's view.
  54. * Bindable Readline Commands:: A description of most of the Readline commands
  55. available for binding
  56. * Readline vi Mode:: A short description of how to make Readline
  57. behave like the vi editor.
  58. @ifset BashFeatures
  59. * Programmable Completion:: How to specify the possible completions for
  60. a specific command.
  61. * Programmable Completion Builtins:: Builtin commands to specify how to
  62. complete arguments for a particular command.
  63. * A Programmable Completion Example:: An example shell function for
  64. generating possible completions.
  65. @end ifset
  66. @end menu
  67. @node Introduction and Notation
  68. @section Introduction to Line Editing
  69. The following paragraphs describe the notation used to represent
  70. keystrokes.
  71. The text @kbd{C-k} is read as `Control-K' and describes the character
  72. produced when the @key{k} key is pressed while the Control key
  73. is depressed.
  74. The text @kbd{M-k} is read as `Meta-K' and describes the character
  75. produced when the Meta key (if you have one) is depressed, and the @key{k}
  76. key is pressed.
  77. The Meta key is labeled @key{ALT} on many keyboards.
  78. On keyboards with two keys labeled @key{ALT} (usually to either side of
  79. the space bar), the @key{ALT} on the left side is generally set to
  80. work as a Meta key.
  81. The @key{ALT} key on the right may also be configured to work as a
  82. Meta key or may be configured as some other modifier, such as a
  83. Compose key for typing accented characters.
  84. If you do not have a Meta or @key{ALT} key, or another key working as
  85. a Meta key, the identical keystroke can be generated by typing @key{ESC}
  86. @emph{first}, and then typing @key{k}.
  87. Either process is known as @dfn{metafying} the @key{k} key.
  88. The text @kbd{M-C-k} is read as `Meta-Control-k' and describes the
  89. character produced by @dfn{metafying} @kbd{C-k}.
  90. In addition, several keys have their own names. Specifically,
  91. @key{DEL}, @key{ESC}, @key{LFD}, @key{SPC}, @key{RET}, and @key{TAB} all
  92. stand for themselves when seen in this text, or in an init file
  93. (@pxref{Readline Init File}).
  94. If your keyboard lacks a @key{LFD} key, typing @key{C-j} will
  95. produce the desired character.
  96. The @key{RET} key may be labeled @key{Return} or @key{Enter} on
  97. some keyboards.
  98. @node Readline Interaction
  99. @section Readline Interaction
  100. @cindex interaction, readline
  101. Often during an interactive session you type in a long line of text,
  102. only to notice that the first word on the line is misspelled. The
  103. Readline library gives you a set of commands for manipulating the text
  104. as you type it in, allowing you to just fix your typo, and not forcing
  105. you to retype the majority of the line. Using these editing commands,
  106. you move the cursor to the place that needs correction, and delete or
  107. insert the text of the corrections. Then, when you are satisfied with
  108. the line, you simply press @key{RET}. You do not have to be at the
  109. end of the line to press @key{RET}; the entire line is accepted
  110. regardless of the location of the cursor within the line.
  111. @menu
  112. * Readline Bare Essentials:: The least you need to know about Readline.
  113. * Readline Movement Commands:: Moving about the input line.
  114. * Readline Killing Commands:: How to delete text, and how to get it back!
  115. * Readline Arguments:: Giving numeric arguments to commands.
  116. * Searching:: Searching through previous lines.
  117. @end menu
  118. @node Readline Bare Essentials
  119. @subsection Readline Bare Essentials
  120. @cindex notation, readline
  121. @cindex command editing
  122. @cindex editing command lines
  123. In order to enter characters into the line, simply type them. The typed
  124. character appears where the cursor was, and then the cursor moves one
  125. space to the right. If you mistype a character, you can use your
  126. erase character to back up and delete the mistyped character.
  127. Sometimes you may mistype a character, and
  128. not notice the error until you have typed several other characters. In
  129. that case, you can type @kbd{C-b} to move the cursor to the left, and then
  130. correct your mistake. Afterwards, you can move the cursor to the right
  131. with @kbd{C-f}.
  132. When you add text in the middle of a line, you will notice that characters
  133. to the right of the cursor are `pushed over' to make room for the text
  134. that you have inserted. Likewise, when you delete text behind the cursor,
  135. characters to the right of the cursor are `pulled back' to fill in the
  136. blank space created by the removal of the text. A list of the bare
  137. essentials for editing the text of an input line follows.
  138. @table @asis
  139. @item @kbd{C-b}
  140. Move back one character.
  141. @item @kbd{C-f}
  142. Move forward one character.
  143. @item @key{DEL} or @key{Backspace}
  144. Delete the character to the left of the cursor.
  145. @item @kbd{C-d}
  146. Delete the character underneath the cursor.
  147. @item @w{Printing characters}
  148. Insert the character into the line at the cursor.
  149. @item @kbd{C-_} or @kbd{C-x C-u}
  150. Undo the last editing command. You can undo all the way back to an
  151. empty line.
  152. @end table
  153. @noindent
  154. (Depending on your configuration, the @key{Backspace} key be set to
  155. delete the character to the left of the cursor and the @key{DEL} key set
  156. to delete the character underneath the cursor, like @kbd{C-d}, rather
  157. than the character to the left of the cursor.)
  158. @node Readline Movement Commands
  159. @subsection Readline Movement Commands
  160. The above table describes the most basic keystrokes that you need
  161. in order to do editing of the input line. For your convenience, many
  162. other commands have been added in addition to @kbd{C-b}, @kbd{C-f},
  163. @kbd{C-d}, and @key{DEL}. Here are some commands for moving more rapidly
  164. about the line.
  165. @table @kbd
  166. @item C-a
  167. Move to the start of the line.
  168. @item C-e
  169. Move to the end of the line.
  170. @item M-f
  171. Move forward a word, where a word is composed of letters and digits.
  172. @item M-b
  173. Move backward a word.
  174. @item C-l
  175. Clear the screen, reprinting the current line at the top.
  176. @end table
  177. Notice how @kbd{C-f} moves forward a character, while @kbd{M-f} moves
  178. forward a word. It is a loose convention that control keystrokes
  179. operate on characters while meta keystrokes operate on words.
  180. @node Readline Killing Commands
  181. @subsection Readline Killing Commands
  182. @cindex killing text
  183. @cindex yanking text
  184. @dfn{Killing} text means to delete the text from the line, but to save
  185. it away for later use, usually by @dfn{yanking} (re-inserting)
  186. it back into the line.
  187. (`Cut' and `paste' are more recent jargon for `kill' and `yank'.)
  188. If the description for a command says that it `kills' text, then you can
  189. be sure that you can get the text back in a different (or the same)
  190. place later.
  191. When you use a kill command, the text is saved in a @dfn{kill-ring}.
  192. Any number of consecutive kills save all of the killed text together, so
  193. that when you yank it back, you get it all. The kill
  194. ring is not line specific; the text that you killed on a previously
  195. typed line is available to be yanked back later, when you are typing
  196. another line.
  197. @cindex kill ring
  198. Here is the list of commands for killing text.
  199. @table @kbd
  200. @item C-k
  201. Kill the text from the current cursor position to the end of the line.
  202. @item M-d
  203. Kill from the cursor to the end of the current word, or, if between
  204. words, to the end of the next word.
  205. Word boundaries are the same as those used by @kbd{M-f}.
  206. @item M-@key{DEL}
  207. Kill from the cursor the start of the current word, or, if between
  208. words, to the start of the previous word.
  209. Word boundaries are the same as those used by @kbd{M-b}.
  210. @item C-w
  211. Kill from the cursor to the previous whitespace. This is different than
  212. @kbd{M-@key{DEL}} because the word boundaries differ.
  213. @end table
  214. Here is how to @dfn{yank} the text back into the line. Yanking
  215. means to copy the most-recently-killed text from the kill buffer.
  216. @table @kbd
  217. @item C-y
  218. Yank the most recently killed text back into the buffer at the cursor.
  219. @item M-y
  220. Rotate the kill-ring, and yank the new top. You can only do this if
  221. the prior command is @kbd{C-y} or @kbd{M-y}.
  222. @end table
  223. @node Readline Arguments
  224. @subsection Readline Arguments
  225. You can pass numeric arguments to Readline commands. Sometimes the
  226. argument acts as a repeat count, other times it is the @i{sign} of the
  227. argument that is significant. If you pass a negative argument to a
  228. command which normally acts in a forward direction, that command will
  229. act in a backward direction. For example, to kill text back to the
  230. start of the line, you might type @samp{M-- C-k}.
  231. The general way to pass numeric arguments to a command is to type meta
  232. digits before the command. If the first `digit' typed is a minus
  233. sign (@samp{-}), then the sign of the argument will be negative. Once
  234. you have typed one meta digit to get the argument started, you can type
  235. the remainder of the digits, and then the command. For example, to give
  236. the @kbd{C-d} command an argument of 10, you could type @samp{M-1 0 C-d},
  237. which will delete the next ten characters on the input line.
  238. @node Searching
  239. @subsection Searching for Commands in the History
  240. Readline provides commands for searching through the command history
  241. @ifset BashFeatures
  242. (@pxref{Bash History Facilities})
  243. @end ifset
  244. for lines containing a specified string.
  245. There are two search modes: @dfn{incremental} and @dfn{non-incremental}.
  246. Incremental searches begin before the user has finished typing the
  247. search string.
  248. As each character of the search string is typed, Readline displays
  249. the next entry from the history matching the string typed so far.
  250. An incremental search requires only as many characters as needed to
  251. find the desired history entry.
  252. To search backward in the history for a particular string, type
  253. @kbd{C-r}. Typing @kbd{C-s} searches forward through the history.
  254. The characters present in the value of the @code{isearch-terminators} variable
  255. are used to terminate an incremental search.
  256. If that variable has not been assigned a value, the @key{ESC} and
  257. @kbd{C-J} characters will terminate an incremental search.
  258. @kbd{C-g} will abort an incremental search and restore the original line.
  259. When the search is terminated, the history entry containing the
  260. search string becomes the current line.
  261. To find other matching entries in the history list, type @kbd{C-r} or
  262. @kbd{C-s} as appropriate.
  263. This will search backward or forward in the history for the next
  264. entry matching the search string typed so far.
  265. Any other key sequence bound to a Readline command will terminate
  266. the search and execute that command.
  267. For instance, a @key{RET} will terminate the search and accept
  268. the line, thereby executing the command from the history list.
  269. A movement command will terminate the search, make the last line found
  270. the current line, and begin editing.
  271. Readline remembers the last incremental search string. If two
  272. @kbd{C-r}s are typed without any intervening characters defining a new
  273. search string, any remembered search string is used.
  274. Non-incremental searches read the entire search string before starting
  275. to search for matching history lines. The search string may be
  276. typed by the user or be part of the contents of the current line.
  277. @node Readline Init File
  278. @section Readline Init File
  279. @cindex initialization file, readline
  280. Although the Readline library comes with a set of Emacs-like
  281. keybindings installed by default, it is possible to use a different set
  282. of keybindings.
  283. Any user can customize programs that use Readline by putting
  284. commands in an @dfn{inputrc} file, conventionally in his home directory.
  285. The name of this
  286. @ifset BashFeatures
  287. file is taken from the value of the shell variable @env{INPUTRC}. If
  288. @end ifset
  289. @ifclear BashFeatures
  290. file is taken from the value of the environment variable @env{INPUTRC}. If
  291. @end ifclear
  292. that variable is unset, the default is @file{~/.inputrc}. If that
  293. file does not exist or cannot be read, the ultimate default is
  294. @file{/etc/inputrc}.
  295. When a program which uses the Readline library starts up, the
  296. init file is read, and the key bindings are set.
  297. In addition, the @code{C-x C-r} command re-reads this init file, thus
  298. incorporating any changes that you might have made to it.
  299. @menu
  300. * Readline Init File Syntax:: Syntax for the commands in the inputrc file.
  301. * Conditional Init Constructs:: Conditional key bindings in the inputrc file.
  302. * Sample Init File:: An example inputrc file.
  303. @end menu
  304. @node Readline Init File Syntax
  305. @subsection Readline Init File Syntax
  306. There are only a few basic constructs allowed in the
  307. Readline init file. Blank lines are ignored.
  308. Lines beginning with a @samp{#} are comments.
  309. Lines beginning with a @samp{$} indicate conditional
  310. constructs (@pxref{Conditional Init Constructs}). Other lines
  311. denote variable settings and key bindings.
  312. @table @asis
  313. @item Variable Settings
  314. You can modify the run-time behavior of Readline by
  315. altering the values of variables in Readline
  316. using the @code{set} command within the init file.
  317. The syntax is simple:
  318. @example
  319. set @var{variable} @var{value}
  320. @end example
  321. @noindent
  322. Here, for example, is how to
  323. change from the default Emacs-like key binding to use
  324. @code{vi} line editing commands:
  325. @example
  326. set editing-mode vi
  327. @end example
  328. Variable names and values, where appropriate, are recognized without regard
  329. to case. Unrecognized variable names are ignored.
  330. Boolean variables (those that can be set to on or off) are set to on if
  331. the value is null or empty, @var{on} (case-insensitive), or 1. Any other
  332. value results in the variable being set to off.
  333. @ifset BashFeatures
  334. The @w{@code{bind -V}} command lists the current Readline variable names
  335. and values. @xref{Bash Builtins}.
  336. @end ifset
  337. A great deal of run-time behavior is changeable with the following
  338. variables.
  339. @cindex variables, readline
  340. @table @code
  341. @item bell-style
  342. @vindex bell-style
  343. Controls what happens when Readline wants to ring the terminal bell.
  344. If set to @samp{none}, Readline never rings the bell. If set to
  345. @samp{visible}, Readline uses a visible bell if one is available.
  346. If set to @samp{audible} (the default), Readline attempts to ring
  347. the terminal's bell.
  348. @item bind-tty-special-chars
  349. @vindex bind-tty-special-chars
  350. If set to @samp{on} (the default), Readline attempts to bind the control
  351. characters treated specially by the kernel's terminal driver to their
  352. Readline equivalents.
  353. @item blink-matching-paren
  354. @vindex blink-matching-paren
  355. If set to @samp{on}, Readline attempts to briefly move the cursor to an
  356. opening parenthesis when a closing parenthesis is inserted. The default
  357. is @samp{off}.
  358. @item colored-completion-prefix
  359. @vindex colored-completion-prefix
  360. If set to @samp{on}, when listing completions, Readline displays the
  361. common prefix of the set of possible completions using a different color.
  362. The color definitions are taken from the value of the @env{LS_COLORS}
  363. environment variable.
  364. The default is @samp{off}.
  365. @item colored-stats
  366. @vindex colored-stats
  367. If set to @samp{on}, Readline displays possible completions using different
  368. colors to indicate their file type.
  369. The color definitions are taken from the value of the @env{LS_COLORS}
  370. environment variable.
  371. The default is @samp{off}.
  372. @item comment-begin
  373. @vindex comment-begin
  374. The string to insert at the beginning of the line when the
  375. @code{insert-comment} command is executed. The default value
  376. is @code{"#"}.
  377. @item completion-display-width
  378. @vindex completion-display-width
  379. The number of screen columns used to display possible matches
  380. when performing completion.
  381. The value is ignored if it is less than 0 or greater than the terminal
  382. screen width.
  383. A value of 0 will cause matches to be displayed one per line.
  384. The default value is -1.
  385. @item completion-ignore-case
  386. @vindex completion-ignore-case
  387. If set to @samp{on}, Readline performs filename matching and completion
  388. in a case-insensitive fashion.
  389. The default value is @samp{off}.
  390. @item completion-map-case
  391. @vindex completion-map-case
  392. If set to @samp{on}, and @var{completion-ignore-case} is enabled, Readline
  393. treats hyphens (@samp{-}) and underscores (@samp{_}) as equivalent when
  394. performing case-insensitive filename matching and completion.
  395. The default value is @samp{off}.
  396. @item completion-prefix-display-length
  397. @vindex completion-prefix-display-length
  398. The length in characters of the common prefix of a list of possible
  399. completions that is displayed without modification. When set to a
  400. value greater than zero, common prefixes longer than this value are
  401. replaced with an ellipsis when displaying possible completions.
  402. @item completion-query-items
  403. @vindex completion-query-items
  404. The number of possible completions that determines when the user is
  405. asked whether the list of possibilities should be displayed.
  406. If the number of possible completions is greater than this value,
  407. Readline will ask the user whether or not he wishes to view
  408. them; otherwise, they are simply listed.
  409. This variable must be set to an integer value greater than or equal to 0.
  410. A negative value means Readline should never ask.
  411. The default limit is @code{100}.
  412. @item convert-meta
  413. @vindex convert-meta
  414. If set to @samp{on}, Readline will convert characters with the
  415. eighth bit set to an @sc{ascii} key sequence by stripping the eighth
  416. bit and prefixing an @key{ESC} character, converting them to a
  417. meta-prefixed key sequence. The default value is @samp{on}, but
  418. will be set to @samp{off} if the locale is one that contains
  419. eight-bit characters.
  420. @item disable-completion
  421. @vindex disable-completion
  422. If set to @samp{On}, Readline will inhibit word completion.
  423. Completion characters will be inserted into the line as if they had
  424. been mapped to @code{self-insert}. The default is @samp{off}.
  425. @item echo-control-characters
  426. @vindex echo-control-characters
  427. When set to @samp{on}, on operating systems that indicate they support it,
  428. readline echoes a character corresponding to a signal generated from the
  429. keyboard. The default is @samp{on}.
  430. @item editing-mode
  431. @vindex editing-mode
  432. The @code{editing-mode} variable controls which default set of
  433. key bindings is used. By default, Readline starts up in Emacs editing
  434. mode, where the keystrokes are most similar to Emacs. This variable can be
  435. set to either @samp{emacs} or @samp{vi}.
  436. @item emacs-mode-string
  437. @vindex emacs-mode-string
  438. If the @var{show-mode-in-prompt} variable is enabled,
  439. this string is displayed immediately before the last line of the primary
  440. prompt when emacs editing mode is active. The value is expanded like a
  441. key binding, so the standard set of meta- and control prefixes and
  442. backslash escape sequences is available.
  443. Use the @samp{\1} and @samp{\2} escapes to begin and end sequences of
  444. non-printing characters, which can be used to embed a terminal control
  445. sequence into the mode string.
  446. The default is @samp{@@}.
  447. @item enable-bracketed-paste
  448. @vindex enable-bracketed-paste
  449. When set to @samp{On}, Readline will configure the terminal in a way
  450. that will enable it to insert each paste into the editing buffer as a
  451. single string of characters, instead of treating each character as if
  452. it had been read from the keyboard. This can prevent pasted characters
  453. from being interpreted as editing commands. The default is @samp{off}.
  454. @item enable-keypad
  455. @vindex enable-keypad
  456. When set to @samp{on}, Readline will try to enable the application
  457. keypad when it is called. Some systems need this to enable the
  458. arrow keys. The default is @samp{off}.
  459. @item enable-meta-key
  460. When set to @samp{on}, Readline will try to enable any meta modifier
  461. key the terminal claims to support when it is called. On many terminals,
  462. the meta key is used to send eight-bit characters.
  463. The default is @samp{on}.
  464. @item expand-tilde
  465. @vindex expand-tilde
  466. If set to @samp{on}, tilde expansion is performed when Readline
  467. attempts word completion. The default is @samp{off}.
  468. @item history-preserve-point
  469. @vindex history-preserve-point
  470. If set to @samp{on}, the history code attempts to place the point (the
  471. current cursor position) at the
  472. same location on each history line retrieved with @code{previous-history}
  473. or @code{next-history}. The default is @samp{off}.
  474. @item history-size
  475. @vindex history-size
  476. Set the maximum number of history entries saved in the history list.
  477. If set to zero, any existing history entries are deleted and no new entries
  478. are saved.
  479. If set to a value less than zero, the number of history entries is not
  480. limited.
  481. By default, the number of history entries is not limited.
  482. If an attempt is made to set @var{history-size} to a non-numeric value,
  483. the maximum number of history entries will be set to 500.
  484. @item horizontal-scroll-mode
  485. @vindex horizontal-scroll-mode
  486. This variable can be set to either @samp{on} or @samp{off}. Setting it
  487. to @samp{on} means that the text of the lines being edited will scroll
  488. horizontally on a single screen line when they are longer than the width
  489. of the screen, instead of wrapping onto a new screen line. By default,
  490. this variable is set to @samp{off}.
  491. @item input-meta
  492. @vindex input-meta
  493. @vindex meta-flag
  494. If set to @samp{on}, Readline will enable eight-bit input (it
  495. will not clear the eighth bit in the characters it reads),
  496. regardless of what the terminal claims it can support. The
  497. default value is @samp{off}, but Readline will set it to @samp{on} if the
  498. locale contains eight-bit characters.
  499. The name @code{meta-flag} is a synonym for this variable.
  500. @item isearch-terminators
  501. @vindex isearch-terminators
  502. The string of characters that should terminate an incremental search without
  503. subsequently executing the character as a command (@pxref{Searching}).
  504. If this variable has not been given a value, the characters @key{ESC} and
  505. @kbd{C-J} will terminate an incremental search.
  506. @item keymap
  507. @vindex keymap
  508. Sets Readline's idea of the current keymap for key binding commands.
  509. Built-in @code{keymap} names are
  510. @code{emacs},
  511. @code{emacs-standard},
  512. @code{emacs-meta},
  513. @code{emacs-ctlx},
  514. @code{vi},
  515. @code{vi-move},
  516. @code{vi-command}, and
  517. @code{vi-insert}.
  518. @code{vi} is equivalent to @code{vi-command} (@code{vi-move} is also a
  519. synonym); @code{emacs} is equivalent to @code{emacs-standard}.
  520. Applications may add additional names.
  521. The default value is @code{emacs}.
  522. The value of the @code{editing-mode} variable also affects the
  523. default keymap.
  524. @item keyseq-timeout
  525. Specifies the duration Readline will wait for a character when reading an
  526. ambiguous key sequence (one that can form a complete key sequence using
  527. the input read so far, or can take additional input to complete a longer
  528. key sequence).
  529. If no input is received within the timeout, Readline will use the shorter
  530. but complete key sequence.
  531. Readline uses this value to determine whether or not input is
  532. available on the current input source (@code{rl_instream} by default).
  533. The value is specified in milliseconds, so a value of 1000 means that
  534. Readline will wait one second for additional input.
  535. If this variable is set to a value less than or equal to zero, or to a
  536. non-numeric value, Readline will wait until another key is pressed to
  537. decide which key sequence to complete.
  538. The default value is @code{500}.
  539. @item mark-directories
  540. If set to @samp{on}, completed directory names have a slash
  541. appended. The default is @samp{on}.
  542. @item mark-modified-lines
  543. @vindex mark-modified-lines
  544. This variable, when set to @samp{on}, causes Readline to display an
  545. asterisk (@samp{*}) at the start of history lines which have been modified.
  546. This variable is @samp{off} by default.
  547. @item mark-symlinked-directories
  548. @vindex mark-symlinked-directories
  549. If set to @samp{on}, completed names which are symbolic links
  550. to directories have a slash appended (subject to the value of
  551. @code{mark-directories}).
  552. The default is @samp{off}.
  553. @item match-hidden-files
  554. @vindex match-hidden-files
  555. This variable, when set to @samp{on}, causes Readline to match files whose
  556. names begin with a @samp{.} (hidden files) when performing filename
  557. completion.
  558. If set to @samp{off}, the leading @samp{.} must be
  559. supplied by the user in the filename to be completed.
  560. This variable is @samp{on} by default.
  561. @item menu-complete-display-prefix
  562. @vindex menu-complete-display-prefix
  563. If set to @samp{on}, menu completion displays the common prefix of the
  564. list of possible completions (which may be empty) before cycling through
  565. the list. The default is @samp{off}.
  566. @item output-meta
  567. @vindex output-meta
  568. If set to @samp{on}, Readline will display characters with the
  569. eighth bit set directly rather than as a meta-prefixed escape
  570. sequence.
  571. The default is @samp{off}, but Readline will set it to @samp{on} if the
  572. locale contains eight-bit characters.
  573. @item page-completions
  574. @vindex page-completions
  575. If set to @samp{on}, Readline uses an internal @code{more}-like pager
  576. to display a screenful of possible completions at a time.
  577. This variable is @samp{on} by default.
  578. @item print-completions-horizontally
  579. If set to @samp{on}, Readline will display completions with matches
  580. sorted horizontally in alphabetical order, rather than down the screen.
  581. The default is @samp{off}.
  582. @item revert-all-at-newline
  583. @vindex revert-all-at-newline
  584. If set to @samp{on}, Readline will undo all changes to history lines
  585. before returning when @code{accept-line} is executed. By default,
  586. history lines may be modified and retain individual undo lists across
  587. calls to @code{readline}. The default is @samp{off}.
  588. @item show-all-if-ambiguous
  589. @vindex show-all-if-ambiguous
  590. This alters the default behavior of the completion functions. If
  591. set to @samp{on},
  592. words which have more than one possible completion cause the
  593. matches to be listed immediately instead of ringing the bell.
  594. The default value is @samp{off}.
  595. @item show-all-if-unmodified
  596. @vindex show-all-if-unmodified
  597. This alters the default behavior of the completion functions in
  598. a fashion similar to @var{show-all-if-ambiguous}.
  599. If set to @samp{on},
  600. words which have more than one possible completion without any
  601. possible partial completion (the possible completions don't share
  602. a common prefix) cause the matches to be listed immediately instead
  603. of ringing the bell.
  604. The default value is @samp{off}.
  605. @item show-mode-in-prompt
  606. @vindex show-mode-in-prompt
  607. If set to @samp{on}, add a string to the beginning of the prompt
  608. indicating the editing mode: emacs, vi command, or vi insertion.
  609. The mode strings are user-settable (e.g., @var{emacs-mode-string}).
  610. The default value is @samp{off}.
  611. @item skip-completed-text
  612. @vindex skip-completed-text
  613. If set to @samp{on}, this alters the default completion behavior when
  614. inserting a single match into the line. It's only active when
  615. performing completion in the middle of a word. If enabled, readline
  616. does not insert characters from the completion that match characters
  617. after point in the word being completed, so portions of the word
  618. following the cursor are not duplicated.
  619. For instance, if this is enabled, attempting completion when the cursor
  620. is after the @samp{e} in @samp{Makefile} will result in @samp{Makefile}
  621. rather than @samp{Makefilefile}, assuming there is a single possible
  622. completion.
  623. The default value is @samp{off}.
  624. @item vi-cmd-mode-string
  625. @vindex vi-cmd-mode-string
  626. If the @var{show-mode-in-prompt} variable is enabled,
  627. this string is displayed immediately before the last line of the primary
  628. prompt when vi editing mode is active and in command mode.
  629. The value is expanded like a
  630. key binding, so the standard set of meta- and control prefixes and
  631. backslash escape sequences is available.
  632. Use the @samp{\1} and @samp{\2} escapes to begin and end sequences of
  633. non-printing characters, which can be used to embed a terminal control
  634. sequence into the mode string.
  635. The default is @samp{(cmd)}.
  636. @item vi-ins-mode-string
  637. @vindex vi-ins-mode-string
  638. If the @var{show-mode-in-prompt} variable is enabled,
  639. this string is displayed immediately before the last line of the primary
  640. prompt when vi editing mode is active and in insertion mode.
  641. The value is expanded like a
  642. key binding, so the standard set of meta- and control prefixes and
  643. backslash escape sequences is available.
  644. Use the @samp{\1} and @samp{\2} escapes to begin and end sequences of
  645. non-printing characters, which can be used to embed a terminal control
  646. sequence into the mode string.
  647. The default is @samp{(ins)}.
  648. @item visible-stats
  649. @vindex visible-stats
  650. If set to @samp{on}, a character denoting a file's type
  651. is appended to the filename when listing possible
  652. completions. The default is @samp{off}.
  653. @end table
  654. @item Key Bindings
  655. The syntax for controlling key bindings in the init file is
  656. simple. First you need to find the name of the command that you
  657. want to change. The following sections contain tables of the command
  658. name, the default keybinding, if any, and a short description of what
  659. the command does.
  660. Once you know the name of the command, simply place on a line
  661. in the init file the name of the key
  662. you wish to bind the command to, a colon, and then the name of the
  663. command.
  664. There can be no space between the key name and the colon -- that will be
  665. interpreted as part of the key name.
  666. The name of the key can be expressed in different ways, depending on
  667. what you find most comfortable.
  668. In addition to command names, readline allows keys to be bound
  669. to a string that is inserted when the key is pressed (a @var{macro}).
  670. @ifset BashFeatures
  671. The @w{@code{bind -p}} command displays Readline function names and
  672. bindings in a format that can put directly into an initialization file.
  673. @xref{Bash Builtins}.
  674. @end ifset
  675. @table @asis
  676. @item @w{@var{keyname}: @var{function-name} or @var{macro}}
  677. @var{keyname} is the name of a key spelled out in English. For example:
  678. @example
  679. Control-u: universal-argument
  680. Meta-Rubout: backward-kill-word
  681. Control-o: "> output"
  682. @end example
  683. In the example above, @kbd{C-u} is bound to the function
  684. @code{universal-argument},
  685. @kbd{M-DEL} is bound to the function @code{backward-kill-word}, and
  686. @kbd{C-o} is bound to run the macro
  687. expressed on the right hand side (that is, to insert the text
  688. @samp{> output} into the line).
  689. A number of symbolic character names are recognized while
  690. processing this key binding syntax:
  691. @var{DEL},
  692. @var{ESC},
  693. @var{ESCAPE},
  694. @var{LFD},
  695. @var{NEWLINE},
  696. @var{RET},
  697. @var{RETURN},
  698. @var{RUBOUT},
  699. @var{SPACE},
  700. @var{SPC},
  701. and
  702. @var{TAB}.
  703. @item @w{"@var{keyseq}": @var{function-name} or @var{macro}}
  704. @var{keyseq} differs from @var{keyname} above in that strings
  705. denoting an entire key sequence can be specified, by placing
  706. the key sequence in double quotes. Some @sc{gnu} Emacs style key
  707. escapes can be used, as in the following example, but the
  708. special character names are not recognized.
  709. @example
  710. "\C-u": universal-argument
  711. "\C-x\C-r": re-read-init-file
  712. "\e[11~": "Function Key 1"
  713. @end example
  714. In the above example, @kbd{C-u} is again bound to the function
  715. @code{universal-argument} (just as it was in the first example),
  716. @samp{@kbd{C-x} @kbd{C-r}} is bound to the function @code{re-read-init-file},
  717. and @samp{@key{ESC} @key{[} @key{1} @key{1} @key{~}} is bound to insert
  718. the text @samp{Function Key 1}.
  719. @end table
  720. The following @sc{gnu} Emacs style escape sequences are available when
  721. specifying key sequences:
  722. @table @code
  723. @item @kbd{\C-}
  724. control prefix
  725. @item @kbd{\M-}
  726. meta prefix
  727. @item @kbd{\e}
  728. an escape character
  729. @item @kbd{\\}
  730. backslash
  731. @item @kbd{\"}
  732. @key{"}, a double quotation mark
  733. @item @kbd{\'}
  734. @key{'}, a single quote or apostrophe
  735. @end table
  736. In addition to the @sc{gnu} Emacs style escape sequences, a second
  737. set of backslash escapes is available:
  738. @table @code
  739. @item \a
  740. alert (bell)
  741. @item \b
  742. backspace
  743. @item \d
  744. delete
  745. @item \f
  746. form feed
  747. @item \n
  748. newline
  749. @item \r
  750. carriage return
  751. @item \t
  752. horizontal tab
  753. @item \v
  754. vertical tab
  755. @item \@var{nnn}
  756. the eight-bit character whose value is the octal value @var{nnn}
  757. (one to three digits)
  758. @item \x@var{HH}
  759. the eight-bit character whose value is the hexadecimal value @var{HH}
  760. (one or two hex digits)
  761. @end table
  762. When entering the text of a macro, single or double quotes must
  763. be used to indicate a macro definition.
  764. Unquoted text is assumed to be a function name.
  765. In the macro body, the backslash escapes described above are expanded.
  766. Backslash will quote any other character in the macro text,
  767. including @samp{"} and @samp{'}.
  768. For example, the following binding will make @samp{@kbd{C-x} \}
  769. insert a single @samp{\} into the line:
  770. @example
  771. "\C-x\\": "\\"
  772. @end example
  773. @end table
  774. @node Conditional Init Constructs
  775. @subsection Conditional Init Constructs
  776. Readline implements a facility similar in spirit to the conditional
  777. compilation features of the C preprocessor which allows key
  778. bindings and variable settings to be performed as the result
  779. of tests. There are four parser directives used.
  780. @table @code
  781. @item $if
  782. The @code{$if} construct allows bindings to be made based on the
  783. editing mode, the terminal being used, or the application using
  784. Readline. The text of the test, after any comparison operator,
  785. extends to the end of the line;
  786. unless otherwise noted, no characters are required to isolate it.
  787. @table @code
  788. @item mode
  789. The @code{mode=} form of the @code{$if} directive is used to test
  790. whether Readline is in @code{emacs} or @code{vi} mode.
  791. This may be used in conjunction
  792. with the @samp{set keymap} command, for instance, to set bindings in
  793. the @code{emacs-standard} and @code{emacs-ctlx} keymaps only if
  794. Readline is starting out in @code{emacs} mode.
  795. @item term
  796. The @code{term=} form may be used to include terminal-specific
  797. key bindings, perhaps to bind the key sequences output by the
  798. terminal's function keys. The word on the right side of the
  799. @samp{=} is tested against both the full name of the terminal and
  800. the portion of the terminal name before the first @samp{-}. This
  801. allows @code{sun} to match both @code{sun} and @code{sun-cmd},
  802. for instance.
  803. @item version
  804. The @code{version} test may be used to perform comparisons against
  805. specific Readline versions.
  806. The @code{version} expands to the current Readline version.
  807. The set of comparison operators includes
  808. @samp{=} (and @samp{==}), @samp{!=}, @samp{<=}, @samp{>=}, @samp{<},
  809. and @samp{>}.
  810. The version number supplied on the right side of the operator consists
  811. of a major version number, an optional decimal point, and an optional
  812. minor version (e.g., @samp{7.1}). If the minor version is omitted, it
  813. is assumed to be @samp{0}.
  814. The operator may be separated from the string @code{version} and
  815. from the version number argument by whitespace.
  816. The following example sets a variable if the Readline version being used
  817. is 7.0 or newer:
  818. @example
  819. $if version >= 7.0
  820. set show-mode-in-prompt on
  821. $endif
  822. @end example
  823. @item application
  824. The @var{application} construct is used to include
  825. application-specific settings. Each program using the Readline
  826. library sets the @var{application name}, and you can test for
  827. a particular value.
  828. This could be used to bind key sequences to functions useful for
  829. a specific program. For instance, the following command adds a
  830. key sequence that quotes the current or previous word in Bash:
  831. @example
  832. $if Bash
  833. # Quote the current or previous word
  834. "\C-xq": "\eb\"\ef\""
  835. $endif
  836. @end example
  837. @item variable
  838. The @var{variable} construct provides simple equality tests for Readline
  839. variables and values.
  840. The permitted comparison operators are @samp{=}, @samp{==}, and @samp{!=}.
  841. The variable name must be separated from the comparison operator by
  842. whitespace; the operator may be separated from the value on the right hand
  843. side by whitespace.
  844. Both string and boolean variables may be tested. Boolean variables must be
  845. tested against the values @var{on} and @var{off}.
  846. The following example is equivalent to the @code{mode=emacs} test described
  847. above:
  848. @example
  849. $if editing-mode == emacs
  850. set show-mode-in-prompt on
  851. $endif
  852. @end example
  853. @end table
  854. @item $endif
  855. This command, as seen in the previous example, terminates an
  856. @code{$if} command.
  857. @item $else
  858. Commands in this branch of the @code{$if} directive are executed if
  859. the test fails.
  860. @item $include
  861. This directive takes a single filename as an argument and reads commands
  862. and bindings from that file.
  863. For example, the following directive reads from @file{/etc/inputrc}:
  864. @example
  865. $include /etc/inputrc
  866. @end example
  867. @end table
  868. @node Sample Init File
  869. @subsection Sample Init File
  870. Here is an example of an @var{inputrc} file. This illustrates key
  871. binding, variable assignment, and conditional syntax.
  872. @example
  873. @page
  874. # This file controls the behaviour of line input editing for
  875. # programs that use the GNU Readline library. Existing
  876. # programs include FTP, Bash, and GDB.
  877. #
  878. # You can re-read the inputrc file with C-x C-r.
  879. # Lines beginning with '#' are comments.
  880. #
  881. # First, include any system-wide bindings and variable
  882. # assignments from /etc/Inputrc
  883. $include /etc/Inputrc
  884. #
  885. # Set various bindings for emacs mode.
  886. set editing-mode emacs
  887. $if mode=emacs
  888. Meta-Control-h: backward-kill-word Text after the function name is ignored
  889. #
  890. # Arrow keys in keypad mode
  891. #
  892. #"\M-OD": backward-char
  893. #"\M-OC": forward-char
  894. #"\M-OA": previous-history
  895. #"\M-OB": next-history
  896. #
  897. # Arrow keys in ANSI mode
  898. #
  899. "\M-[D": backward-char
  900. "\M-[C": forward-char
  901. "\M-[A": previous-history
  902. "\M-[B": next-history
  903. #
  904. # Arrow keys in 8 bit keypad mode
  905. #
  906. #"\M-\C-OD": backward-char
  907. #"\M-\C-OC": forward-char
  908. #"\M-\C-OA": previous-history
  909. #"\M-\C-OB": next-history
  910. #
  911. # Arrow keys in 8 bit ANSI mode
  912. #
  913. #"\M-\C-[D": backward-char
  914. #"\M-\C-[C": forward-char
  915. #"\M-\C-[A": previous-history
  916. #"\M-\C-[B": next-history
  917. C-q: quoted-insert
  918. $endif
  919. # An old-style binding. This happens to be the default.
  920. TAB: complete
  921. # Macros that are convenient for shell interaction
  922. $if Bash
  923. # edit the path
  924. "\C-xp": "PATH=$@{PATH@}\e\C-e\C-a\ef\C-f"
  925. # prepare to type a quoted word --
  926. # insert open and close double quotes
  927. # and move to just after the open quote
  928. "\C-x\"": "\"\"\C-b"
  929. # insert a backslash (testing backslash escapes
  930. # in sequences and macros)
  931. "\C-x\\": "\\"
  932. # Quote the current or previous word
  933. "\C-xq": "\eb\"\ef\""
  934. # Add a binding to refresh the line, which is unbound
  935. "\C-xr": redraw-current-line
  936. # Edit variable on current line.
  937. "\M-\C-v": "\C-a\C-k$\C-y\M-\C-e\C-a\C-y="
  938. $endif
  939. # use a visible bell if one is available
  940. set bell-style visible
  941. # don't strip characters to 7 bits when reading
  942. set input-meta on
  943. # allow iso-latin1 characters to be inserted rather
  944. # than converted to prefix-meta sequences
  945. set convert-meta off
  946. # display characters with the eighth bit set directly
  947. # rather than as meta-prefixed characters
  948. set output-meta on
  949. # if there are more than 150 possible completions for
  950. # a word, ask the user if he wants to see all of them
  951. set completion-query-items 150
  952. # For FTP
  953. $if Ftp
  954. "\C-xg": "get \M-?"
  955. "\C-xt": "put \M-?"
  956. "\M-.": yank-last-arg
  957. $endif
  958. @end example
  959. @node Bindable Readline Commands
  960. @section Bindable Readline Commands
  961. @menu
  962. * Commands For Moving:: Moving about the line.
  963. * Commands For History:: Getting at previous lines.
  964. * Commands For Text:: Commands for changing text.
  965. * Commands For Killing:: Commands for killing and yanking.
  966. * Numeric Arguments:: Specifying numeric arguments, repeat counts.
  967. * Commands For Completion:: Getting Readline to do the typing for you.
  968. * Keyboard Macros:: Saving and re-executing typed characters
  969. * Miscellaneous Commands:: Other miscellaneous commands.
  970. @end menu
  971. This section describes Readline commands that may be bound to key
  972. sequences.
  973. @ifset BashFeatures
  974. You can list your key bindings by executing
  975. @w{@code{bind -P}} or, for a more terse format, suitable for an
  976. @var{inputrc} file, @w{@code{bind -p}}. (@xref{Bash Builtins}.)
  977. @end ifset
  978. Command names without an accompanying key sequence are unbound by default.
  979. In the following descriptions, @dfn{point} refers to the current cursor
  980. position, and @dfn{mark} refers to a cursor position saved by the
  981. @code{set-mark} command.
  982. The text between the point and mark is referred to as the @dfn{region}.
  983. @node Commands For Moving
  984. @subsection Commands For Moving
  985. @ftable @code
  986. @item beginning-of-line (C-a)
  987. Move to the start of the current line.
  988. @item end-of-line (C-e)
  989. Move to the end of the line.
  990. @item forward-char (C-f)
  991. Move forward a character.
  992. @item backward-char (C-b)
  993. Move back a character.
  994. @item forward-word (M-f)
  995. Move forward to the end of the next word.
  996. Words are composed of letters and digits.
  997. @item backward-word (M-b)
  998. Move back to the start of the current or previous word.
  999. Words are composed of letters and digits.
  1000. @ifset BashFeatures
  1001. @item shell-forward-word ()
  1002. Move forward to the end of the next word.
  1003. Words are delimited by non-quoted shell metacharacters.
  1004. @item shell-backward-word ()
  1005. Move back to the start of the current or previous word.
  1006. Words are delimited by non-quoted shell metacharacters.
  1007. @end ifset
  1008. @item previous-screen-line ()
  1009. Attempt to move point to the same physical screen column on the previous
  1010. physical screen line. This will not have the desired effect if the current
  1011. Readline line does not take up more than one physical line or if point is not
  1012. greater than the length of the prompt plus the screen width.
  1013. @item next-screen-line ()
  1014. Attempt to move point to the same physical screen column on the next
  1015. physical screen line. This will not have the desired effect if the current
  1016. Readline line does not take up more than one physical line or if the length
  1017. of the current Readline line is not greater than the length of the prompt
  1018. plus the screen width.
  1019. @item clear-screen (C-l)
  1020. Clear the screen and redraw the current line,
  1021. leaving the current line at the top of the screen.
  1022. @item redraw-current-line ()
  1023. Refresh the current line. By default, this is unbound.
  1024. @end ftable
  1025. @node Commands For History
  1026. @subsection Commands For Manipulating The History
  1027. @ftable @code
  1028. @item accept-line (Newline or Return)
  1029. @ifset BashFeatures
  1030. Accept the line regardless of where the cursor is.
  1031. If this line is
  1032. non-empty, add it to the history list according to the setting of
  1033. the @env{HISTCONTROL} and @env{HISTIGNORE} variables.
  1034. If this line is a modified history line, then restore the history line
  1035. to its original state.
  1036. @end ifset
  1037. @ifclear BashFeatures
  1038. Accept the line regardless of where the cursor is.
  1039. If this line is
  1040. non-empty, it may be added to the history list for future recall with
  1041. @code{add_history()}.
  1042. If this line is a modified history line, the history line is restored
  1043. to its original state.
  1044. @end ifclear
  1045. @item previous-history (C-p)
  1046. Move `back' through the history list, fetching the previous command.
  1047. @item next-history (C-n)
  1048. Move `forward' through the history list, fetching the next command.
  1049. @item beginning-of-history (M-<)
  1050. Move to the first line in the history.
  1051. @item end-of-history (M->)
  1052. Move to the end of the input history, i.e., the line currently
  1053. being entered.
  1054. @item reverse-search-history (C-r)
  1055. Search backward starting at the current line and moving `up' through
  1056. the history as necessary. This is an incremental search.
  1057. @item forward-search-history (C-s)
  1058. Search forward starting at the current line and moving `down' through
  1059. the history as necessary. This is an incremental search.
  1060. @item non-incremental-reverse-search-history (M-p)
  1061. Search backward starting at the current line and moving `up'
  1062. through the history as necessary using a non-incremental search
  1063. for a string supplied by the user.
  1064. The search string may match anywhere in a history line.
  1065. @item non-incremental-forward-search-history (M-n)
  1066. Search forward starting at the current line and moving `down'
  1067. through the history as necessary using a non-incremental search
  1068. for a string supplied by the user.
  1069. The search string may match anywhere in a history line.
  1070. @item history-search-forward ()
  1071. Search forward through the history for the string of characters
  1072. between the start of the current line and the point.
  1073. The search string must match at the beginning of a history line.
  1074. This is a non-incremental search.
  1075. By default, this command is unbound.
  1076. @item history-search-backward ()
  1077. Search backward through the history for the string of characters
  1078. between the start of the current line and the point.
  1079. The search string must match at the beginning of a history line.
  1080. This is a non-incremental search.
  1081. By default, this command is unbound.
  1082. @item history-substring-search-forward ()
  1083. Search forward through the history for the string of characters
  1084. between the start of the current line and the point.
  1085. The search string may match anywhere in a history line.
  1086. This is a non-incremental search.
  1087. By default, this command is unbound.
  1088. @item history-substring-search-backward ()
  1089. Search backward through the history for the string of characters
  1090. between the start of the current line and the point.
  1091. The search string may match anywhere in a history line.
  1092. This is a non-incremental search.
  1093. By default, this command is unbound.
  1094. @item yank-nth-arg (M-C-y)
  1095. Insert the first argument to the previous command (usually
  1096. the second word on the previous line) at point.
  1097. With an argument @var{n},
  1098. insert the @var{n}th word from the previous command (the words
  1099. in the previous command begin with word 0). A negative argument
  1100. inserts the @var{n}th word from the end of the previous command.
  1101. Once the argument @var{n} is computed, the argument is extracted
  1102. as if the @samp{!@var{n}} history expansion had been specified.
  1103. @item yank-last-arg (M-. or M-_)
  1104. Insert last argument to the previous command (the last word of the
  1105. previous history entry).
  1106. With a numeric argument, behave exactly like @code{yank-nth-arg}.
  1107. Successive calls to @code{yank-last-arg} move back through the history
  1108. list, inserting the last word (or the word specified by the argument to
  1109. the first call) of each line in turn.
  1110. Any numeric argument supplied to these successive calls determines
  1111. the direction to move through the history. A negative argument switches
  1112. the direction through the history (back or forward).
  1113. The history expansion facilities are used to extract the last argument,
  1114. as if the @samp{!$} history expansion had been specified.
  1115. @end ftable
  1116. @node Commands For Text
  1117. @subsection Commands For Changing Text
  1118. @ftable @code
  1119. @item @i{end-of-file} (usually C-d)
  1120. The character indicating end-of-file as set, for example, by
  1121. @code{stty}. If this character is read when there are no characters
  1122. on the line, and point is at the beginning of the line, Readline
  1123. interprets it as the end of input and returns @sc{eof}.
  1124. @item delete-char (C-d)
  1125. Delete the character at point. If this function is bound to the
  1126. same character as the tty @sc{eof} character, as @kbd{C-d}
  1127. commonly is, see above for the effects.
  1128. @item backward-delete-char (Rubout)
  1129. Delete the character behind the cursor. A numeric argument means
  1130. to kill the characters instead of deleting them.
  1131. @item forward-backward-delete-char ()
  1132. Delete the character under the cursor, unless the cursor is at the
  1133. end of the line, in which case the character behind the cursor is
  1134. deleted. By default, this is not bound to a key.
  1135. @item quoted-insert (C-q or C-v)
  1136. Add the next character typed to the line verbatim. This is
  1137. how to insert key sequences like @kbd{C-q}, for example.
  1138. @ifclear BashFeatures
  1139. @item tab-insert (M-@key{TAB})
  1140. Insert a tab character.
  1141. @end ifclear
  1142. @item self-insert (a, b, A, 1, !, @dots{})
  1143. Insert yourself.
  1144. @item bracketed-paste-begin ()
  1145. This function is intended to be bound to the "bracketed paste" escape
  1146. sequence sent by some terminals, and such a binding is assigned by default.
  1147. It allows Readline to insert the pasted text as a single unit without treating
  1148. each character as if it had been read from the keyboard. The characters
  1149. are inserted as if each one was bound to @code{self-insert} instead of
  1150. executing any editing commands.
  1151. @item transpose-chars (C-t)
  1152. Drag the character before the cursor forward over
  1153. the character at the cursor, moving the
  1154. cursor forward as well. If the insertion point
  1155. is at the end of the line, then this
  1156. transposes the last two characters of the line.
  1157. Negative arguments have no effect.
  1158. @item transpose-words (M-t)
  1159. Drag the word before point past the word after point,
  1160. moving point past that word as well.
  1161. If the insertion point is at the end of the line, this transposes
  1162. the last two words on the line.
  1163. @item upcase-word (M-u)
  1164. Uppercase the current (or following) word. With a negative argument,
  1165. uppercase the previous word, but do not move the cursor.
  1166. @item downcase-word (M-l)
  1167. Lowercase the current (or following) word. With a negative argument,
  1168. lowercase the previous word, but do not move the cursor.
  1169. @item capitalize-word (M-c)
  1170. Capitalize the current (or following) word. With a negative argument,
  1171. capitalize the previous word, but do not move the cursor.
  1172. @item overwrite-mode ()
  1173. Toggle overwrite mode. With an explicit positive numeric argument,
  1174. switches to overwrite mode. With an explicit non-positive numeric
  1175. argument, switches to insert mode. This command affects only
  1176. @code{emacs} mode; @code{vi} mode does overwrite differently.
  1177. Each call to @code{readline()} starts in insert mode.
  1178. In overwrite mode, characters bound to @code{self-insert} replace
  1179. the text at point rather than pushing the text to the right.
  1180. Characters bound to @code{backward-delete-char} replace the character
  1181. before point with a space.
  1182. By default, this command is unbound.
  1183. @end ftable
  1184. @node Commands For Killing
  1185. @subsection Killing And Yanking
  1186. @ftable @code
  1187. @item kill-line (C-k)
  1188. Kill the text from point to the end of the line.
  1189. @item backward-kill-line (C-x Rubout)
  1190. Kill backward from the cursor to the beginning of the current line.
  1191. @item unix-line-discard (C-u)
  1192. Kill backward from the cursor to the beginning of the current line.
  1193. @item kill-whole-line ()
  1194. Kill all characters on the current line, no matter where point is.
  1195. By default, this is unbound.
  1196. @item kill-word (M-d)
  1197. Kill from point to the end of the current word, or if between
  1198. words, to the end of the next word.
  1199. Word boundaries are the same as @code{forward-word}.
  1200. @item backward-kill-word (M-@key{DEL})
  1201. Kill the word behind point.
  1202. Word boundaries are the same as @code{backward-word}.
  1203. @ifset BashFeatures
  1204. @item shell-kill-word ()
  1205. Kill from point to the end of the current word, or if between
  1206. words, to the end of the next word.
  1207. Word boundaries are the same as @code{shell-forward-word}.
  1208. @item shell-backward-kill-word ()
  1209. Kill the word behind point.
  1210. Word boundaries are the same as @code{shell-backward-word}.
  1211. @end ifset
  1212. @item unix-word-rubout (C-w)
  1213. Kill the word behind point, using white space as a word boundary.
  1214. The killed text is saved on the kill-ring.
  1215. @item unix-filename-rubout ()
  1216. Kill the word behind point, using white space and the slash character
  1217. as the word boundaries.
  1218. The killed text is saved on the kill-ring.
  1219. @item delete-horizontal-space ()
  1220. Delete all spaces and tabs around point. By default, this is unbound.
  1221. @item kill-region ()
  1222. Kill the text in the current region.
  1223. By default, this command is unbound.
  1224. @item copy-region-as-kill ()
  1225. Copy the text in the region to the kill buffer, so it can be yanked
  1226. right away. By default, this command is unbound.
  1227. @item copy-backward-word ()
  1228. Copy the word before point to the kill buffer.
  1229. The word boundaries are the same as @code{backward-word}.
  1230. By default, this command is unbound.
  1231. @item copy-forward-word ()
  1232. Copy the word following point to the kill buffer.
  1233. The word boundaries are the same as @code{forward-word}.
  1234. By default, this command is unbound.
  1235. @item yank (C-y)
  1236. Yank the top of the kill ring into the buffer at point.
  1237. @item yank-pop (M-y)
  1238. Rotate the kill-ring, and yank the new top. You can only do this if
  1239. the prior command is @code{yank} or @code{yank-pop}.
  1240. @end ftable
  1241. @node Numeric Arguments
  1242. @subsection Specifying Numeric Arguments
  1243. @ftable @code
  1244. @item digit-argument (@kbd{M-0}, @kbd{M-1}, @dots{} @kbd{M--})
  1245. Add this digit to the argument already accumulating, or start a new
  1246. argument. @kbd{M--} starts a negative argument.
  1247. @item universal-argument ()
  1248. This is another way to specify an argument.
  1249. If this command is followed by one or more digits, optionally with a
  1250. leading minus sign, those digits define the argument.
  1251. If the command is followed by digits, executing @code{universal-argument}
  1252. again ends the numeric argument, but is otherwise ignored.
  1253. As a special case, if this command is immediately followed by a
  1254. character that is neither a digit nor minus sign, the argument count
  1255. for the next command is multiplied by four.
  1256. The argument count is initially one, so executing this function the
  1257. first time makes the argument count four, a second time makes the
  1258. argument count sixteen, and so on.
  1259. By default, this is not bound to a key.
  1260. @end ftable
  1261. @node Commands For Completion
  1262. @subsection Letting Readline Type For You
  1263. @ftable @code
  1264. @item complete (@key{TAB})
  1265. Attempt to perform completion on the text before point.
  1266. The actual completion performed is application-specific.
  1267. @ifset BashFeatures
  1268. Bash attempts completion treating the text as a variable (if the
  1269. text begins with @samp{$}), username (if the text begins with
  1270. @samp{~}), hostname (if the text begins with @samp{@@}), or
  1271. command (including aliases and functions) in turn. If none
  1272. of these produces a match, filename completion is attempted.
  1273. @end ifset
  1274. @ifclear BashFeatures
  1275. The default is filename completion.
  1276. @end ifclear
  1277. @item possible-completions (M-?)
  1278. List the possible completions of the text before point.
  1279. When displaying completions, Readline sets the number of columns used
  1280. for display to the value of @code{completion-display-width}, the value of
  1281. the environment variable @env{COLUMNS}, or the screen width, in that order.
  1282. @item insert-completions (M-*)
  1283. Insert all completions of the text before point that would have
  1284. been generated by @code{possible-completions}.
  1285. @item menu-complete ()
  1286. Similar to @code{complete}, but replaces the word to be completed
  1287. with a single match from the list of possible completions.
  1288. Repeated execution of @code{menu-complete} steps through the list
  1289. of possible completions, inserting each match in turn.
  1290. At the end of the list of completions, the bell is rung
  1291. (subject to the setting of @code{bell-style})
  1292. and the original text is restored.
  1293. An argument of @var{n} moves @var{n} positions forward in the list
  1294. of matches; a negative argument may be used to move backward
  1295. through the list.
  1296. This command is intended to be bound to @key{TAB}, but is unbound
  1297. by default.
  1298. @item menu-complete-backward ()
  1299. Identical to @code{menu-complete}, but moves backward through the list
  1300. of possible completions, as if @code{menu-complete} had been given a
  1301. negative argument.
  1302. @item delete-char-or-list ()
  1303. Deletes the character under the cursor if not at the beginning or
  1304. end of the line (like @code{delete-char}).
  1305. If at the end of the line, behaves identically to
  1306. @code{possible-completions}.
  1307. This command is unbound by default.
  1308. @ifset BashFeatures
  1309. @item complete-filename (M-/)
  1310. Attempt filename completion on the text before point.
  1311. @item possible-filename-completions (C-x /)
  1312. List the possible completions of the text before point,
  1313. treating it as a filename.
  1314. @item complete-username (M-~)
  1315. Attempt completion on the text before point, treating
  1316. it as a username.
  1317. @item possible-username-completions (C-x ~)
  1318. List the possible completions of the text before point,
  1319. treating it as a username.
  1320. @item complete-variable (M-$)
  1321. Attempt completion on the text before point, treating
  1322. it as a shell variable.
  1323. @item possible-variable-completions (C-x $)
  1324. List the possible completions of the text before point,
  1325. treating it as a shell variable.
  1326. @item complete-hostname (M-@@)
  1327. Attempt completion on the text before point, treating
  1328. it as a hostname.
  1329. @item possible-hostname-completions (C-x @@)
  1330. List the possible completions of the text before point,
  1331. treating it as a hostname.
  1332. @item complete-command (M-!)
  1333. Attempt completion on the text before point, treating
  1334. it as a command name. Command completion attempts to
  1335. match the text against aliases, reserved words, shell
  1336. functions, shell builtins, and finally executable filenames,
  1337. in that order.
  1338. @item possible-command-completions (C-x !)
  1339. List the possible completions of the text before point,
  1340. treating it as a command name.
  1341. @item dynamic-complete-history (M-@key{TAB})
  1342. Attempt completion on the text before point, comparing
  1343. the text against lines from the history list for possible
  1344. completion matches.
  1345. @item dabbrev-expand ()
  1346. Attempt menu completion on the text before point, comparing
  1347. the text against lines from the history list for possible
  1348. completion matches.
  1349. @item complete-into-braces (M-@{)
  1350. Perform filename completion and insert the list of possible completions
  1351. enclosed within braces so the list is available to the shell
  1352. (@pxref{Brace Expansion}).
  1353. @end ifset
  1354. @end ftable
  1355. @node Keyboard Macros
  1356. @subsection Keyboard Macros
  1357. @ftable @code
  1358. @item start-kbd-macro (C-x ()
  1359. Begin saving the characters typed into the current keyboard macro.
  1360. @item end-kbd-macro (C-x ))
  1361. Stop saving the characters typed into the current keyboard macro
  1362. and save the definition.
  1363. @item call-last-kbd-macro (C-x e)
  1364. Re-execute the last keyboard macro defined, by making the characters
  1365. in the macro appear as if typed at the keyboard.
  1366. @item print-last-kbd-macro ()
  1367. Print the last keboard macro defined in a format suitable for the
  1368. @var{inputrc} file.
  1369. @end ftable
  1370. @node Miscellaneous Commands
  1371. @subsection Some Miscellaneous Commands
  1372. @ftable @code
  1373. @item re-read-init-file (C-x C-r)
  1374. Read in the contents of the @var{inputrc} file, and incorporate
  1375. any bindings or variable assignments found there.
  1376. @item abort (C-g)
  1377. Abort the current editing command and
  1378. ring the terminal's bell (subject to the setting of
  1379. @code{bell-style}).
  1380. @item do-lowercase-version (M-A, M-B, M-@var{x}, @dots{})
  1381. If the metafied character @var{x} is upper case, run the command
  1382. that is bound to the corresponding metafied lower case character.
  1383. The behavior is undefined if @var{x} is already lower case.
  1384. @item prefix-meta (@key{ESC})
  1385. Metafy the next character typed. This is for keyboards
  1386. without a meta key. Typing @samp{@key{ESC} f} is equivalent to typing
  1387. @kbd{M-f}.
  1388. @item undo (C-_ or C-x C-u)
  1389. Incremental undo, separately remembered for each line.
  1390. @item revert-line (M-r)
  1391. Undo all changes made to this line. This is like executing the @code{undo}
  1392. command enough times to get back to the beginning.
  1393. @ifset BashFeatures
  1394. @item tilde-expand (M-&)
  1395. @end ifset
  1396. @ifclear BashFeatures
  1397. @item tilde-expand (M-~)
  1398. @end ifclear
  1399. Perform tilde expansion on the current word.
  1400. @item set-mark (C-@@)
  1401. Set the mark to the point. If a
  1402. numeric argument is supplied, the mark is set to that position.
  1403. @item exchange-point-and-mark (C-x C-x)
  1404. Swap the point with the mark. The current cursor position is set to
  1405. the saved position, and the old cursor position is saved as the mark.
  1406. @item character-search (C-])
  1407. A character is read and point is moved to the next occurrence of that
  1408. character. A negative count searches for previous occurrences.
  1409. @item character-search-backward (M-C-])
  1410. A character is read and point is moved to the previous occurrence
  1411. of that character. A negative count searches for subsequent
  1412. occurrences.
  1413. @item skip-csi-sequence ()
  1414. Read enough characters to consume a multi-key sequence such as those
  1415. defined for keys like Home and End. Such sequences begin with a
  1416. Control Sequence Indicator (CSI), usually ESC-[. If this sequence is
  1417. bound to "\e[", keys producing such sequences will have no effect
  1418. unless explicitly bound to a readline command, instead of inserting
  1419. stray characters into the editing buffer. This is unbound by default,
  1420. but usually bound to ESC-[.
  1421. @item insert-comment (M-#)
  1422. Without a numeric argument, the value of the @code{comment-begin}
  1423. variable is inserted at the beginning of the current line.
  1424. If a numeric argument is supplied, this command acts as a toggle: if
  1425. the characters at the beginning of the line do not match the value
  1426. of @code{comment-begin}, the value is inserted, otherwise
  1427. the characters in @code{comment-begin} are deleted from the beginning of
  1428. the line.
  1429. In either case, the line is accepted as if a newline had been typed.
  1430. @ifset BashFeatures
  1431. The default value of @code{comment-begin} causes this command
  1432. to make the current line a shell comment.
  1433. If a numeric argument causes the comment character to be removed, the line
  1434. will be executed by the shell.
  1435. @end ifset
  1436. @item dump-functions ()
  1437. Print all of the functions and their key bindings to the
  1438. Readline output stream. If a numeric argument is supplied,
  1439. the output is formatted in such a way that it can be made part
  1440. of an @var{inputrc} file. This command is unbound by default.
  1441. @item dump-variables ()
  1442. Print all of the settable variables and their values to the
  1443. Readline output stream. If a numeric argument is supplied,
  1444. the output is formatted in such a way that it can be made part
  1445. of an @var{inputrc} file. This command is unbound by default.
  1446. @item dump-macros ()
  1447. Print all of the Readline key sequences bound to macros and the
  1448. strings they output. If a numeric argument is supplied,
  1449. the output is formatted in such a way that it can be made part
  1450. of an @var{inputrc} file. This command is unbound by default.
  1451. @ifset BashFeatures
  1452. @item glob-complete-word (M-g)
  1453. The word before point is treated as a pattern for pathname expansion,
  1454. with an asterisk implicitly appended. This pattern is used to
  1455. generate a list of matching file names for possible completions.
  1456. @item glob-expand-word (C-x *)
  1457. The word before point is treated as a pattern for pathname expansion,
  1458. and the list of matching file names is inserted, replacing the word.
  1459. If a numeric argument is supplied, a @samp{*} is appended before
  1460. pathname expansion.
  1461. @item glob-list-expansions (C-x g)
  1462. The list of expansions that would have been generated by
  1463. @code{glob-expand-word} is displayed, and the line is redrawn.
  1464. If a numeric argument is supplied, a @samp{*} is appended before
  1465. pathname expansion.
  1466. @item display-shell-version (C-x C-v)
  1467. Display version information about the current instance of Bash.
  1468. @item shell-expand-line (M-C-e)
  1469. Expand the line as the shell does.
  1470. This performs alias and history expansion as well as all of the shell
  1471. word expansions (@pxref{Shell Expansions}).
  1472. @item history-expand-line (M-^)
  1473. Perform history expansion on the current line.
  1474. @item magic-space ()
  1475. Perform history expansion on the current line and insert a space
  1476. (@pxref{History Interaction}).
  1477. @item alias-expand-line ()
  1478. Perform alias expansion on the current line (@pxref{Aliases}).
  1479. @item history-and-alias-expand-line ()
  1480. Perform history and alias expansion on the current line.
  1481. @item insert-last-argument (M-. or M-_)
  1482. A synonym for @code{yank-last-arg}.
  1483. @item operate-and-get-next (C-o)
  1484. Accept the current line for execution and fetch the next line
  1485. relative to the current line from the history for editing.
  1486. A numeric argument, if supplied, specifies the history entry to use instead
  1487. of the current line.
  1488. @item edit-and-execute-command (C-x C-e)
  1489. Invoke an editor on the current command line, and execute the result as shell
  1490. commands.
  1491. Bash attempts to invoke
  1492. @code{$VISUAL}, @code{$EDITOR}, and @code{emacs}
  1493. as the editor, in that order.
  1494. @end ifset
  1495. @ifclear BashFeatures
  1496. @item emacs-editing-mode (C-e)
  1497. When in @code{vi} command mode, this causes a switch to @code{emacs}
  1498. editing mode.
  1499. @item vi-editing-mode (M-C-j)
  1500. When in @code{emacs} editing mode, this causes a switch to @code{vi}
  1501. editing mode.
  1502. @end ifclear
  1503. @end ftable
  1504. @node Readline vi Mode
  1505. @section Readline vi Mode
  1506. While the Readline library does not have a full set of @code{vi}
  1507. editing functions, it does contain enough to allow simple editing
  1508. of the line. The Readline @code{vi} mode behaves as specified in
  1509. the @sc{posix} standard.
  1510. @ifset BashFeatures
  1511. In order to switch interactively between @code{emacs} and @code{vi}
  1512. editing modes, use the @samp{set -o emacs} and @samp{set -o vi}
  1513. commands (@pxref{The Set Builtin}).
  1514. @end ifset
  1515. @ifclear BashFeatures
  1516. In order to switch interactively between @code{emacs} and @code{vi}
  1517. editing modes, use the command @kbd{M-C-j} (bound to emacs-editing-mode
  1518. when in @code{vi} mode and to vi-editing-mode in @code{emacs} mode).
  1519. @end ifclear
  1520. The Readline default is @code{emacs} mode.
  1521. When you enter a line in @code{vi} mode, you are already placed in
  1522. `insertion' mode, as if you had typed an @samp{i}. Pressing @key{ESC}
  1523. switches you into `command' mode, where you can edit the text of the
  1524. line with the standard @code{vi} movement keys, move to previous
  1525. history lines with @samp{k} and subsequent lines with @samp{j}, and
  1526. so forth.
  1527. @ifset BashFeatures
  1528. @node Programmable Completion
  1529. @section Programmable Completion
  1530. @cindex programmable completion
  1531. When word completion is attempted for an argument to a command for
  1532. which a completion specification (a @var{compspec}) has been defined
  1533. using the @code{complete} builtin (@pxref{Programmable Completion Builtins}),
  1534. the programmable completion facilities are invoked.
  1535. First, the command name is identified.
  1536. If a compspec has been defined for that command, the
  1537. compspec is used to generate the list of possible completions for the word.
  1538. If the command word is the empty string (completion attempted at the
  1539. beginning of an empty line), any compspec defined with
  1540. the @option{-E} option to @code{complete} is used.
  1541. If the command word is a full pathname, a compspec for the full
  1542. pathname is searched for first.
  1543. If no compspec is found for the full pathname, an attempt is made to
  1544. find a compspec for the portion following the final slash.
  1545. If those searches do not result in a compspec, any compspec defined with
  1546. the @option{-D} option to @code{complete} is used as the default.
  1547. If there is no default compspec, Bash attempts alias expansion
  1548. on the command word as a final resort, and attempts to find a compspec
  1549. for the command word from any successful expansion
  1550. Once a compspec has been found, it is used to generate the list of
  1551. matching words.
  1552. If a compspec is not found, the default Bash completion
  1553. described above (@pxref{Commands For Completion}) is performed.
  1554. First, the actions specified by the compspec are used.
  1555. Only matches which are prefixed by the word being completed are
  1556. returned.
  1557. When the @option{-f} or @option{-d} option is used for filename or
  1558. directory name completion, the shell variable @env{FIGNORE} is
  1559. used to filter the matches.
  1560. @xref{Bash Variables}, for a description of @env{FIGNORE}.
  1561. Any completions specified by a filename expansion pattern to the
  1562. @option{-G} option are generated next.
  1563. The words generated by the pattern need not match the word being completed.
  1564. The @env{GLOBIGNORE} shell variable is not used to filter the matches,
  1565. but the @env{FIGNORE} shell variable is used.
  1566. Next, the string specified as the argument to the @option{-W} option
  1567. is considered.
  1568. The string is first split using the characters in the @env{IFS}
  1569. special variable as delimiters.
  1570. Shell quoting is honored within the string, in order to provide a
  1571. mechanism for the words to contain shell metacharacters or characters
  1572. in the value of @env{IFS}.
  1573. Each word is then expanded using
  1574. brace expansion, tilde expansion, parameter and variable expansion,
  1575. command substitution, and arithmetic expansion,
  1576. as described above (@pxref{Shell Expansions}).
  1577. The results are split using the rules described above
  1578. (@pxref{Word Splitting}).
  1579. The results of the expansion are prefix-matched against the word being
  1580. completed, and the matching words become the possible completions.
  1581. After these matches have been generated, any shell function or command
  1582. specified with the @option{-F} and @option{-C} options is invoked.
  1583. When the command or function is invoked, the @env{COMP_LINE},
  1584. @env{COMP_POINT}, @env{COMP_KEY}, and @env{COMP_TYPE} variables are
  1585. assigned values as described above (@pxref{Bash Variables}).
  1586. If a shell function is being invoked, the @env{COMP_WORDS} and
  1587. @env{COMP_CWORD} variables are also set.
  1588. When the function or command is invoked, the first argument ($1) is the
  1589. name of the command whose arguments are being completed, the
  1590. second argument ($2) is the word being completed, and the third argument
  1591. ($3) is the word preceding the word being completed on the current command
  1592. line.
  1593. No filtering of the generated completions against the word being completed
  1594. is performed; the function or command has complete freedom in generating
  1595. the matches.
  1596. Any function specified with @option{-F} is invoked first.
  1597. The function may use any of the shell facilities, including the
  1598. @code{compgen} and @code{compopt} builtins described below
  1599. (@pxref{Programmable Completion Builtins}), to generate the matches.
  1600. It must put the possible completions in the @env{COMPREPLY} array
  1601. variable, one per array element.
  1602. Next, any command specified with the @option{-C} option is invoked
  1603. in an environment equivalent to command substitution.
  1604. It should print a list of completions, one per line, to
  1605. the standard output.
  1606. Backslash may be used to escape a newline, if necessary.
  1607. After all of the possible completions are generated, any filter
  1608. specified with the @option{-X} option is applied to the list.
  1609. The filter is a pattern as used for pathname expansion; a @samp{&}
  1610. in the pattern is replaced with the text of the word being completed.
  1611. A literal @samp{&} may be escaped with a backslash; the backslash
  1612. is removed before attempting a match.
  1613. Any completion that matches the pattern will be removed from the list.
  1614. A leading @samp{!} negates the pattern; in this case any completion
  1615. not matching the pattern will be removed.
  1616. If the @code{nocasematch} shell option
  1617. (see the description of @code{shopt} in @ref{The Shopt Builtin})
  1618. is enabled, the match is performed without regard to the case
  1619. of alphabetic characters.
  1620. Finally, any prefix and suffix specified with the @option{-P} and @option{-S}
  1621. options are added to each member of the completion list, and the result is
  1622. returned to the Readline completion code as the list of possible
  1623. completions.
  1624. If the previously-applied actions do not generate any matches, and the
  1625. @option{-o dirnames} option was supplied to @code{complete} when the
  1626. compspec was defined, directory name completion is attempted.
  1627. If the @option{-o plusdirs} option was supplied to @code{complete} when
  1628. the compspec was defined, directory name completion is attempted and any
  1629. matches are added to the results of the other actions.
  1630. By default, if a compspec is found, whatever it generates is returned to
  1631. the completion code as the full set of possible completions.
  1632. The default Bash completions are not attempted, and the Readline default
  1633. of filename completion is disabled.
  1634. If the @option{-o bashdefault} option was supplied to @code{complete} when
  1635. the compspec was defined, the default Bash completions are attempted
  1636. if the compspec generates no matches.
  1637. If the @option{-o default} option was supplied to @code{complete} when the
  1638. compspec was defined, Readline's default completion will be performed
  1639. if the compspec (and, if attempted, the default Bash completions)
  1640. generate no matches.
  1641. When a compspec indicates that directory name completion is desired,
  1642. the programmable completion functions force Readline to append a slash
  1643. to completed names which are symbolic links to directories, subject to
  1644. the value of the @var{mark-directories} Readline variable, regardless
  1645. of the setting of the @var{mark-symlinked-directories} Readline variable.
  1646. There is some support for dynamically modifying completions. This is
  1647. most useful when used in combination with a default completion specified
  1648. with @option{-D}. It's possible for shell functions executed as completion
  1649. handlers to indicate that completion should be retried by returning an
  1650. exit status of 124. If a shell function returns 124, and changes
  1651. the compspec associated with the command on which completion is being
  1652. attempted (supplied as the first argument when the function is executed),
  1653. programmable completion restarts from the beginning, with an
  1654. attempt to find a new compspec for that command. This allows a set of
  1655. completions to be built dynamically as completion is attempted, rather than
  1656. being loaded all at once.
  1657. For instance, assuming that there is a library of compspecs, each kept in a
  1658. file corresponding to the name of the command, the following default
  1659. completion function would load completions dynamically:
  1660. @example
  1661. _completion_loader()
  1662. @{
  1663. . "/etc/bash_completion.d/$1.sh" >/dev/null 2>&1 && return 124
  1664. @}
  1665. complete -D -F _completion_loader -o bashdefault -o default
  1666. @end example
  1667. @node Programmable Completion Builtins
  1668. @section Programmable Completion Builtins
  1669. @cindex completion builtins
  1670. Three builtin commands are available to manipulate the programmable completion
  1671. facilities: one to specify how the arguments to a particular command are to
  1672. be completed, and two to modify the completion as it is happening.
  1673. @table @code
  1674. @item compgen
  1675. @btindex compgen
  1676. @example
  1677. @code{compgen [@var{option}] [@var{word}]}
  1678. @end example
  1679. Generate possible completion matches for @var{word} according to
  1680. the @var{option}s, which may be any option accepted by the
  1681. @code{complete}
  1682. builtin with the exception of @option{-p} and @option{-r}, and write
  1683. the matches to the standard output.
  1684. When using the @option{-F} or @option{-C} options, the various shell variables
  1685. set by the programmable completion facilities, while available, will not
  1686. have useful values.
  1687. The matches will be generated in the same way as if the programmable
  1688. completion code had generated them directly from a completion specification
  1689. with the same flags.
  1690. If @var{word} is specified, only those completions matching @var{word}
  1691. will be displayed.
  1692. The return value is true unless an invalid option is supplied, or no
  1693. matches were generated.
  1694. @item complete
  1695. @btindex complete
  1696. @example
  1697. @code{complete [-abcdefgjksuv] [-o @var{comp-option}] [-DEI] [-A @var{action}] [-G @var{globpat}]
  1698. [-W @var{wordlist}] [-F @var{function}] [-C @var{command}] [-X @var{filterpat}]
  1699. [-P @var{prefix}] [-S @var{suffix}] @var{name} [@var{name} @dots{}]}
  1700. @code{complete -pr [-DEI] [@var{name} @dots{}]}
  1701. @end example
  1702. Specify how arguments to each @var{name} should be completed.
  1703. If the @option{-p} option is supplied, or if no options are supplied, existing
  1704. completion specifications are printed in a way that allows them to be
  1705. reused as input.
  1706. The @option{-r} option removes a completion specification for
  1707. each @var{name}, or, if no @var{name}s are supplied, all
  1708. completion specifications.
  1709. The @option{-D} option indicates that other supplied options and actions should
  1710. apply to the ``default'' command completion; that is, completion attempted
  1711. on a command for which no completion has previously been defined.
  1712. The @option{-E} option indicates that other supplied options and actions should
  1713. apply to ``empty'' command completion; that is, completion attempted on a
  1714. blank line.
  1715. The @option{-I} option indicates that other supplied options and actions should
  1716. apply to completion on the inital non-assignment word on the line, or after a
  1717. command delimiter such as @samp{;} or @samp{|}, which is usually command
  1718. name completion.
  1719. If multiple options are supplied, the @option{-D} option takes precedence
  1720. over @option{-E}, and both take precedence over @option{-I}.
  1721. If any of @option{-D}, @option{-E}, or @option{-I} are supplied, any other
  1722. @var{name} arguments are ignored; these completions only apply to the case
  1723. specified by the option.
  1724. The process of applying these completion specifications when word completion
  1725. is attempted is described above (@pxref{Programmable Completion}).
  1726. Other options, if specified, have the following meanings.
  1727. The arguments to the @option{-G}, @option{-W}, and @option{-X} options
  1728. (and, if necessary, the @option{-P} and @option{-S} options)
  1729. should be quoted to protect them from expansion before the
  1730. @code{complete} builtin is invoked.
  1731. @table @code
  1732. @item -o @var{comp-option}
  1733. The @var{comp-option} controls several aspects of the compspec's behavior
  1734. beyond the simple generation of completions.
  1735. @var{comp-option} may be one of:
  1736. @table @code
  1737. @item bashdefault
  1738. Perform the rest of the default Bash completions if the compspec
  1739. generates no matches.
  1740. @item default
  1741. Use Readline's default filename completion if the compspec generates
  1742. no matches.
  1743. @item dirnames
  1744. Perform directory name completion if the compspec generates no matches.
  1745. @item filenames
  1746. Tell Readline that the compspec generates filenames, so it can perform any
  1747. filename-specific processing (like adding a slash to directory names,
  1748. quoting special characters, or suppressing trailing spaces).
  1749. This option is intended to be used with shell functions specified
  1750. with @option{-F}.
  1751. @item noquote
  1752. Tell Readline not to quote the completed words if they are filenames
  1753. (quoting filenames is the default).
  1754. @item nosort
  1755. Tell Readline not to sort the list of possible completions alphabetically.
  1756. @item nospace
  1757. Tell Readline not to append a space (the default) to words completed at
  1758. the end of the line.
  1759. @item plusdirs
  1760. After any matches defined by the compspec are generated,
  1761. directory name completion is attempted and any
  1762. matches are added to the results of the other actions.
  1763. @end table
  1764. @item -A @var{action}
  1765. The @var{action} may be one of the following to generate a list of possible
  1766. completions:
  1767. @table @code
  1768. @item alias
  1769. Alias names. May also be specified as @option{-a}.
  1770. @item arrayvar
  1771. Array variable names.
  1772. @item binding
  1773. Readline key binding names (@pxref{Bindable Readline Commands}).
  1774. @item builtin
  1775. Names of shell builtin commands. May also be specified as @option{-b}.
  1776. @item command
  1777. Command names. May also be specified as @option{-c}.
  1778. @item directory
  1779. Directory names. May also be specified as @option{-d}.
  1780. @item disabled
  1781. Names of disabled shell builtins.
  1782. @item enabled
  1783. Names of enabled shell builtins.
  1784. @item export
  1785. Names of exported shell variables. May also be specified as @option{-e}.
  1786. @item file
  1787. File names. May also be specified as @option{-f}.
  1788. @item function
  1789. Names of shell functions.
  1790. @item group
  1791. Group names. May also be specified as @option{-g}.
  1792. @item helptopic
  1793. Help topics as accepted by the @code{help} builtin (@pxref{Bash Builtins}).
  1794. @item hostname
  1795. Hostnames, as taken from the file specified by the
  1796. @env{HOSTFILE} shell variable (@pxref{Bash Variables}).
  1797. @item job
  1798. Job names, if job control is active. May also be specified as @option{-j}.
  1799. @item keyword
  1800. Shell reserved words. May also be specified as @option{-k}.
  1801. @item running
  1802. Names of running jobs, if job control is active.
  1803. @item service
  1804. Service names. May also be specified as @option{-s}.
  1805. @item setopt
  1806. Valid arguments for the @option{-o} option to the @code{set} builtin
  1807. (@pxref{The Set Builtin}).
  1808. @item shopt
  1809. Shell option names as accepted by the @code{shopt} builtin
  1810. (@pxref{Bash Builtins}).
  1811. @item signal
  1812. Signal names.
  1813. @item stopped
  1814. Names of stopped jobs, if job control is active.
  1815. @item user
  1816. User names. May also be specified as @option{-u}.
  1817. @item variable
  1818. Names of all shell variables. May also be specified as @option{-v}.
  1819. @end table
  1820. @item -C @var{command}
  1821. @var{command} is executed in a subshell environment, and its output is
  1822. used as the possible completions.
  1823. @item -F @var{function}
  1824. The shell function @var{function} is executed in the current shell
  1825. environment.
  1826. When it is executed, $1 is the name of the command whose arguments are
  1827. being completed, $2 is the word being completed, and $3 is the word
  1828. preceding the word being completed, as described above
  1829. (@pxref{Programmable Completion}).
  1830. When it finishes, the possible completions are retrieved from the value
  1831. of the @env{COMPREPLY} array variable.
  1832. @item -G @var{globpat}
  1833. The filename expansion pattern @var{globpat} is expanded to generate
  1834. the possible completions.
  1835. @item -P @var{prefix}
  1836. @var{prefix} is added at the beginning of each possible completion
  1837. after all other options have been applied.
  1838. @item -S @var{suffix}
  1839. @var{suffix} is appended to each possible completion
  1840. after all other options have been applied.
  1841. @item -W @var{wordlist}
  1842. The @var{wordlist} is split using the characters in the
  1843. @env{IFS} special variable as delimiters, and each resultant word
  1844. is expanded.
  1845. The possible completions are the members of the resultant list which
  1846. match the word being completed.
  1847. @item -X @var{filterpat}
  1848. @var{filterpat} is a pattern as used for filename expansion.
  1849. It is applied to the list of possible completions generated by the
  1850. preceding options and arguments, and each completion matching
  1851. @var{filterpat} is removed from the list.
  1852. A leading @samp{!} in @var{filterpat} negates the pattern; in this
  1853. case, any completion not matching @var{filterpat} is removed.
  1854. @end table
  1855. The return value is true unless an invalid option is supplied, an option
  1856. other than @option{-p} or @option{-r} is supplied without a @var{name}
  1857. argument, an attempt is made to remove a completion specification for
  1858. a @var{name} for which no specification exists, or
  1859. an error occurs adding a completion specification.
  1860. @item compopt
  1861. @btindex compopt
  1862. @example
  1863. @code{compopt} [-o @var{option}] [-DEI] [+o @var{option}] [@var{name}]
  1864. @end example
  1865. Modify completion options for each @var{name} according to the
  1866. @var{option}s, or for the currently-executing completion if no @var{name}s
  1867. are supplied.
  1868. If no @var{option}s are given, display the completion options for each
  1869. @var{name} or the current completion.
  1870. The possible values of @var{option} are those valid for the @code{complete}
  1871. builtin described above.
  1872. The @option{-D} option indicates that other supplied options should
  1873. apply to the ``default'' command completion; that is, completion attempted
  1874. on a command for which no completion has previously been defined.
  1875. The @option{-E} option indicates that other supplied options should
  1876. apply to ``empty'' command completion; that is, completion attempted on a
  1877. blank line.
  1878. The @option{-I} option indicates that other supplied options should
  1879. apply to completion on the inital non-assignment word on the line, or after a
  1880. command delimiter such as @samp{;} or @samp{|}, which is usually command
  1881. name completion.
  1882. If multiple options are supplied, the @option{-D} option takes precedence
  1883. over @option{-E}, and both take precedence over @option{-I}
  1884. The return value is true unless an invalid option is supplied, an attempt
  1885. is made to modify the options for a @var{name} for which no completion
  1886. specification exists, or an output error occurs.
  1887. @end table
  1888. @node A Programmable Completion Example
  1889. @section A Programmable Completion Example
  1890. The most common way to obtain additional completion functionality beyond
  1891. the default actions @code{complete} and @code{compgen} provide is to use
  1892. a shell function and bind it to a particular command using @code{complete -F}.
  1893. The following function provides completions for the @code{cd} builtin.
  1894. It is a reasonably good example of what shell functions must do when
  1895. used for completion. This function uses the word passed as @code{$2}
  1896. to determine the directory name to complete. You can also use the
  1897. @code{COMP_WORDS} array variable; the current word is indexed by the
  1898. @code{COMP_CWORD} variable.
  1899. The function relies on the @code{complete} and @code{compgen} builtins
  1900. to do much of the work, adding only the things that the Bash @code{cd}
  1901. does beyond accepting basic directory names:
  1902. tilde expansion (@pxref{Tilde Expansion}),
  1903. searching directories in @var{$CDPATH}, which is described above
  1904. (@pxref{Bourne Shell Builtins}),
  1905. and basic support for the @code{cdable_vars} shell option
  1906. (@pxref{The Shopt Builtin}).
  1907. @code{_comp_cd} modifies the value of @var{IFS} so that it contains only
  1908. a newline to accommodate file names containing spaces and tabs --
  1909. @code{compgen} prints the possible completions it generates one per line.
  1910. Possible completions go into the @var{COMPREPLY} array variable, one
  1911. completion per array element. The programmable completion system retrieves
  1912. the completions from there when the function returns.
  1913. @example
  1914. # A completion function for the cd builtin
  1915. # based on the cd completion function from the bash_completion package
  1916. _comp_cd()
  1917. @{
  1918. local IFS=$' \t\n' # normalize IFS
  1919. local cur _skipdot _cdpath
  1920. local i j k
  1921. # Tilde expansion, which also expands tilde to full pathname
  1922. case "$2" in
  1923. \~*) eval cur="$2" ;;
  1924. *) cur=$2 ;;
  1925. esac
  1926. # no cdpath or absolute pathname -- straight directory completion
  1927. if [[ -z "$@{CDPATH:-@}" ]] || [[ "$cur" == @@(./*|../*|/*) ]]; then
  1928. # compgen prints paths one per line; could also use while loop
  1929. IFS=$'\n'
  1930. COMPREPLY=( $(compgen -d -- "$cur") )
  1931. IFS=$' \t\n'
  1932. # CDPATH+directories in the current directory if not in CDPATH
  1933. else
  1934. IFS=$'\n'
  1935. _skipdot=false
  1936. # preprocess CDPATH to convert null directory names to .
  1937. _cdpath=$@{CDPATH/#:/.:@}
  1938. _cdpath=$@{_cdpath//::/:.:@}
  1939. _cdpath=$@{_cdpath/%:/:.@}
  1940. for i in $@{_cdpath//:/$'\n'@}; do
  1941. if [[ $i -ef . ]]; then _skipdot=true; fi
  1942. k="$@{#COMPREPLY[@@]@}"
  1943. for j in $( compgen -d -- "$i/$cur" ); do
  1944. COMPREPLY[k++]=$@{j#$i/@} # cut off directory
  1945. done
  1946. done
  1947. $_skipdot || COMPREPLY+=( $(compgen -d -- "$cur") )
  1948. IFS=$' \t\n'
  1949. fi
  1950. # variable names if appropriate shell option set and no completions
  1951. if shopt -q cdable_vars && [[ $@{#COMPREPLY[@@]@} -eq 0 ]]; then
  1952. COMPREPLY=( $(compgen -v -- "$cur") )
  1953. fi
  1954. return 0
  1955. @}
  1956. @end example
  1957. We install the completion function using the @option{-F} option to
  1958. @code{complete}:
  1959. @example
  1960. # Tell readline to quote appropriate and append slashes to directories;
  1961. # use the bash default completion for other arguments
  1962. complete -o filenames -o nospace -o bashdefault -F _comp_cd cd
  1963. @end example
  1964. @noindent
  1965. Since we'd like Bash and Readline to take care of some
  1966. of the other details for us, we use several other options to tell Bash
  1967. and Readline what to do. The @option{-o filenames} option tells Readline
  1968. that the possible completions should be treated as filenames, and quoted
  1969. appropriately. That option will also cause Readline to append a slash to
  1970. filenames it can determine are directories (which is why we might want to
  1971. extend @code{_comp_cd} to append a slash if we're using directories found
  1972. via @var{CDPATH}: Readline can't tell those completions are directories).
  1973. The @option{-o nospace} option tells Readline to not append a space
  1974. character to the directory name, in case we want to append to it.
  1975. The @option{-o bashdefault} option brings in the rest of the "Bash default"
  1976. completions -- possible completion that Bash adds to the default Readline
  1977. set. These include things like command name completion, variable completion
  1978. for words beginning with @samp{@{}, completions containing pathname
  1979. expansion patterns (@pxref{Filename Expansion}), and so on.
  1980. Once installed using @code{complete}, @code{_comp_cd} will be called every
  1981. time we attempt word completion for a @code{cd} command.
  1982. Many more examples -- an extensive collection of completions for most of
  1983. the common GNU, Unix, and Linux commands -- are available as part of the
  1984. bash_completion project. This is installed by default on many GNU/Linux
  1985. distributions. Originally written by Ian Macdonald, the project now lives
  1986. at @url{http://bash-completion.alioth.debian.org/}. There are ports for
  1987. other systems such as Solaris and Mac OS X.
  1988. An older version of the bash_completion package is distributed with bash
  1989. in the @file{examples/complete} subdirectory.
  1990. @end ifset