Teruhiro Komaki's Blog (Temporary)

Bash(Viモード)の設定やコマンドのメモ

先日、BashをViモードに変更して快適になった話というブログを書きました。

BashをViモードに変更して使うようになってから、快適にターミナルを使っています。

ただ、前の記事では、Viモード時のコマンドについて、全く書いてなかった…

ということで、色々と調べたので、参考になったURLを紹介します

ググり続ける日々

色々なキーワードでググりまして、よい情報があったので、以下にURLを記録しておきます

現在の設定を確認する

以下のコマンドで確認できます

bind -p

出力を見ると、色々と設定されているのが分かります

私は.inputrc"\C-l": clear-screenを設定しているため、反映されています

しかし、設定をコメントアウトするとclear-screen (not bound)となります

また、コマンドモードに切り替えるキーにControl-jを設定していますが、以下の出力から分かるように、デフォルトのキー(Esc)もあるので、色々なキーで設定しても問題ないようです

ということで、キーと任意の値を設定すれば、よさそうです

1"\C-j": vi-movement-mode
2"\e": vi-movement-mode

自分の環境のものをメモ

  1~ $ bind -p
  2
  3# abort (not bound)
  4"\C-m": accept-line
  5# alias-expand-line (not bound)
  6# arrow-key-prefix (not bound)
  7# backward-byte (not bound)
  8"\eOD": backward-char
  9"\e[D": backward-char
 10"\C-h": backward-delete-char
 11"\C-?": backward-delete-char
 12# backward-kill-line (not bound)
 13# backward-kill-word (not bound)
 14# backward-word (not bound)
 15# beginning-of-history (not bound)
 16"\eOH": beginning-of-line
 17"\e[1~": beginning-of-line
 18"\e[H": beginning-of-line
 19"\e[200~": bracketed-paste-begin
 20# call-last-kbd-macro (not bound)
 21# capitalize-word (not bound)
 22# character-search (not bound)
 23# character-search-backward (not bound)
 24"\C-l": clear-screen
 25"\C-i": complete
 26# complete-command (not bound)
 27# complete-filename (not bound)
 28# complete-hostname (not bound)
 29# complete-into-braces (not bound)
 30# complete-username (not bound)
 31# complete-variable (not bound)
 32# copy-backward-word (not bound)
 33# copy-forward-word (not bound)
 34# copy-region-as-kill (not bound)
 35# dabbrev-expand (not bound)
 36"\e[3~": delete-char
 37# delete-char-or-list (not bound)
 38# delete-horizontal-space (not bound)
 39# digit-argument (not bound)
 40# display-shell-version (not bound)
 41# do-lowercase-version (not bound)
 42# downcase-word (not bound)
 43# dump-functions (not bound)
 44# dump-macros (not bound)
 45# dump-variables (not bound)
 46# dynamic-complete-history (not bound)
 47# edit-and-execute-command (not bound)
 48# emacs-editing-mode (not bound)
 49# end-kbd-macro (not bound)
 50# end-of-history (not bound)
 51"\eOF": end-of-line
 52"\e[4~": end-of-line
 53"\e[F": end-of-line
 54# exchange-point-and-mark (not bound)
 55# forward-backward-delete-char (not bound)
 56# forward-byte (not bound)
 57"\eOC": forward-char
 58"\e[C": forward-char
 59"\C-s": forward-search-history
 60# forward-word (not bound)
 61# glob-complete-word (not bound)
 62# glob-expand-word (not bound)
 63# glob-list-expansions (not bound)
 64# history-and-alias-expand-line (not bound)
 65# history-expand-line (not bound)
 66"\C-p": history-search-backward
 67"\C-n": history-search-forward
 68# history-substring-search-backward (not bound)
 69# history-substring-search-forward (not bound)
 70# insert-comment (not bound)
 71# insert-completions (not bound)
 72# insert-last-argument (not bound)
 73# kill-line (not bound)
 74# kill-region (not bound)
 75# kill-whole-line (not bound)
 76# kill-word (not bound)
 77# magic-space (not bound)
 78"TAB": menu-complete
 79"\e[Z": menu-complete-backward
 80"\eOB": next-history
 81"\e[B": next-history
 82# non-incremental-forward-search-history (not bound)
 83# non-incremental-forward-search-history-again (not bound)
 84# non-incremental-reverse-search-history (not bound)
 85# non-incremental-reverse-search-history-again (not bound)
 86# old-menu-complete (not bound)
 87# operate-and-get-next (not bound)
 88# overwrite-mode (not bound)
 89# possible-command-completions (not bound)
 90# possible-completions (not bound)
 91# possible-filename-completions (not bound)
 92# possible-hostname-completions (not bound)
 93# possible-username-completions (not bound)
 94# possible-variable-completions (not bound)
 95"\eOA": previous-history
 96"\e[A": previous-history
 97# print-last-kbd-macro (not bound)
 98"\C-v": quoted-insert
 99# re-read-init-file (not bound)
100# redraw-current-line (not bound)
101"\C-r": reverse-search-history
102# revert-line (not bound)
103"\C-a": self-insert
104"\C-b": self-insert
105"\C-c": self-insert
106"\C-e": self-insert
107"\C-f": self-insert
108"\C-g": self-insert
109"\C-k": self-insert
110"\C-o": self-insert
111"\C-q": self-insert
112"\C-x": self-insert
113"\C-z": self-insert
114"\C-\\": self-insert
115"\C-]": self-insert
116"\C-^": self-insert
117" ": self-insert
118"!": self-insert
119"\"": self-insert
120"#": self-insert
121"$": self-insert
122"%": self-insert
123"&": self-insert
124"'": self-insert
125"(": self-insert
126")": self-insert
127"*": self-insert
128"+": self-insert
129",": self-insert
130"-": self-insert
131".": self-insert
132"/": self-insert
133"0": self-insert
134"1": self-insert
135"2": self-insert
136"3": self-insert
137"4": self-insert
138"5": self-insert
139"6": self-insert
140"7": self-insert
141"8": self-insert
142"9": self-insert
143":": self-insert
144";": self-insert
145"<": self-insert
146"=": self-insert
147">": self-insert
148"?": self-insert
149"@": self-insert
150"A": self-insert
151"B": self-insert
152"C": self-insert
153"D": self-insert
154"E": self-insert
155"F": self-insert
156"G": self-insert
157"H": self-insert
158"I": self-insert
159"J": self-insert
160"K": self-insert
161"L": self-insert
162"M": self-insert
163"N": self-insert
164"O": self-insert
165"P": self-insert
166"Q": self-insert
167"R": self-insert
168"S": self-insert
169"T": self-insert
170"U": self-insert
171"V": self-insert
172"W": self-insert
173"X": self-insert
174"Y": self-insert
175"Z": self-insert
176"[": self-insert
177"\\": self-insert
178"]": self-insert
179"^": self-insert
180"_": self-insert
181"`": self-insert
182"a": self-insert
183"b": self-insert
184"c": self-insert
185"d": self-insert
186"e": self-insert
187"f": self-insert
188"g": self-insert
189"h": self-insert
190"i": self-insert
191"j": self-insert
192"k": self-insert
193"l": self-insert
194"m": self-insert
195"n": self-insert
196"o": self-insert
197"p": self-insert
198"q": self-insert
199"r": self-insert
200"s": self-insert
201"t": self-insert
202"u": self-insert
203"v": self-insert
204"w": self-insert
205"x": self-insert
206"y": self-insert
207"z": self-insert
208"{": self-insert
209"|": self-insert
210"}": self-insert
211"~": self-insert
212"\200": self-insert
213"\201": self-insert
214"\202": self-insert
215"\203": self-insert
216"\204": self-insert
217"\205": self-insert
218"\206": self-insert
219"\207": self-insert
220"\210": self-insert
221"\211": self-insert
222"\212": self-insert
223"\213": self-insert
224"\214": self-insert
225"\215": self-insert
226"\216": self-insert
227"\217": self-insert
228"\220": self-insert
229"\221": self-insert
230"\222": self-insert
231"\223": self-insert
232"\224": self-insert
233"\225": self-insert
234"\226": self-insert
235"\227": self-insert
236"\230": self-insert
237"\231": self-insert
238"\232": self-insert
239"\233": self-insert
240"\234": self-insert
241"\235": self-insert
242"\236": self-insert
243"\237": self-insert
244" ": self-insert
245"¡": self-insert
246"¢": self-insert
247"£": self-insert
248"¤": self-insert
249"¥": self-insert
250"¦": self-insert
251"§": self-insert
252"¨": self-insert
253"©": self-insert
254"ª": self-insert
255"«": self-insert
256"¬": self-insert
257"­": self-insert
258"®": self-insert
259"¯": self-insert
260"°": self-insert
261"±": self-insert
262"²": self-insert
263"³": self-insert
264"´": self-insert
265"µ": self-insert
266"¶": self-insert
267"·": self-insert
268"¸": self-insert
269"¹": self-insert
270"º": self-insert
271"»": self-insert
272"¼": self-insert
273"½": self-insert
274"¾": self-insert
275"¿": self-insert
276"À": self-insert
277"Á": self-insert
278"Â": self-insert
279"Ã": self-insert
280"Ä": self-insert
281"Å": self-insert
282"Æ": self-insert
283"Ç": self-insert
284"È": self-insert
285"É": self-insert
286"Ê": self-insert
287"Ë": self-insert
288"Ì": self-insert
289"Í": self-insert
290"Î": self-insert
291"Ï": self-insert
292"Ð": self-insert
293"Ñ": self-insert
294"Ò": self-insert
295"Ó": self-insert
296"Ô": self-insert
297"Õ": self-insert
298"Ö": self-insert
299"×": self-insert
300"Ø": self-insert
301"Ù": self-insert
302"Ú": self-insert
303"Û": self-insert
304"Ü": self-insert
305"Ý": self-insert
306"Þ": self-insert
307"ß": self-insert
308"à": self-insert
309"á": self-insert
310"â": self-insert
311"ã": self-insert
312"ä": self-insert
313"å": self-insert
314"æ": self-insert
315"ç": self-insert
316"è": self-insert
317"é": self-insert
318"ê": self-insert
319"ë": self-insert
320"ì": self-insert
321"í": self-insert
322"î": self-insert
323"ï": self-insert
324"ð": self-insert
325"ñ": self-insert
326"ò": self-insert
327"ó": self-insert
328"ô": self-insert
329"õ": self-insert
330"ö": self-insert
331"÷": self-insert
332"ø": self-insert
333"ù": self-insert
334"ú": self-insert
335"û": self-insert
336"ü": self-insert
337"ý": self-insert
338"þ": self-insert
339"ÿ": self-insert
340# set-mark (not bound)
341# shell-backward-kill-word (not bound)
342# shell-backward-word (not bound)
343# shell-expand-line (not bound)
344# shell-forward-word (not bound)
345# shell-kill-word (not bound)
346# skip-csi-sequence (not bound)
347# start-kbd-macro (not bound)
348# tab-insert (not bound)
349# tilde-expand (not bound)
350"\C-t": transpose-chars
351# transpose-words (not bound)
352# tty-status (not bound)
353# undo (not bound)
354# universal-argument (not bound)
355# unix-filename-rubout (not bound)
356"\C-u": unix-line-discard
357# unix-word-rubout (not bound)
358# upcase-word (not bound)
359# vi-append-eol (not bound)
360# vi-append-mode (not bound)
361# vi-arg-digit (not bound)
362# vi-bWord (not bound)
363# vi-back-to-indent (not bound)
364# vi-backward-bigword (not bound)
365# vi-backward-word (not bound)
366# vi-bword (not bound)
367# vi-change-case (not bound)
368# vi-change-char (not bound)
369# vi-change-to (not bound)
370# vi-char-search (not bound)
371# vi-column (not bound)
372# vi-complete (not bound)
373# vi-delete (not bound)
374# vi-delete-to (not bound)
375# vi-eWord (not bound)
376# vi-editing-mode (not bound)
377# vi-end-bigword (not bound)
378# vi-end-word (not bound)
379"\C-d": vi-eof-maybe
380# vi-eword (not bound)
381# vi-fWord (not bound)
382# vi-fetch-history (not bound)
383# vi-first-print (not bound)
384# vi-forward-bigword (not bound)
385# vi-forward-word (not bound)
386# vi-fword (not bound)
387# vi-goto-mark (not bound)
388# vi-insert-beg (not bound)
389# vi-insertion-mode (not bound)
390# vi-match (not bound)
391"\C-j": vi-movement-mode
392"\e": vi-movement-mode
393# vi-next-word (not bound)
394# vi-overstrike (not bound)
395# vi-overstrike-delete (not bound)
396# vi-prev-word (not bound)
397# vi-put (not bound)
398# vi-redo (not bound)
399# vi-replace (not bound)
400# vi-rubout (not bound)
401# vi-search (not bound)
402# vi-search-again (not bound)
403# vi-set-mark (not bound)
404# vi-subst (not bound)
405# vi-tilde-expand (not bound)
406"\C-w": vi-unix-word-rubout
407# vi-yank-arg (not bound)
408# vi-yank-pop (not bound)
409# vi-yank-to (not bound)
410"\C-y": yank
411# yank-last-arg (not bound)
412# yank-nth-arg (not bound)
413# yank-pop (not bound)

Working Productively in Bash’s Vi Command Line Editing Mode (ASCII .txt format)

テキストフォーマットは、以下に貼っておきます

  1.---------------------------------------------------------------------------.
  2|                                                                           |
  3|                          Readline VI Editing Mode                         |
  4|                     Default Keyboard Shortcuts for Bash                   |
  5|                               Cheat Sheet                                 |
  6|                                                                           |
  7'---------------------------------------------------------------------------'
  8| Peteris Krumins ([email protected]), 2008.01.08                          |
  9| http://www.catonmat.net  -  good coders code, great reuse                 |
 10|                                                                           |
 11| Released under the GNU Free Document License                              |
 12'---------------------------------------------------------------------------'
 13
 14 ======================== Keyboard Shortcut Summary ========================
 15
 16.--------------.------------------------------------------------------------.
 17|              |                                                            |
 18| Shortcut     | Description                                                |
 19|              |                                                            |
 20'--------------'------------------------------------------------------------'
 21| Switching to COMMAND Mode:                                                |
 22'--------------.------------------------------------------------------------'
 23| ESC          | Switch to command mode.                                    |
 24'--------------'------------------------------------------------------------'
 25| Commands for Entering INPUT Mode:                                         |
 26'--------------.------------------------------------------------------------'
 27| i            | Insert before cursor.                                      |
 28'--------------+------------------------------------------------------------'
 29| a            | Insert after cursor.                                       |
 30'--------------+------------------------------------------------------------'
 31| I            | Insert at the beginning of line.                           |
 32'--------------+------------------------------------------------------------'
 33| A            | Insert at the end of line.                                 |
 34'--------------+------------------------------------------------------------'
 35| c<mov. comm> | Change text of a movement command <mov. comm> (see below). |
 36'--------------+------------------------------------------------------------'
 37| C            | Change text to the end of line (equivalent to c$).         |
 38'--------------+------------------------------------------------------------'
 39| cc or S      | Change current line (equivalent to 0c$).                   |
 40'--------------+------------------------------------------------------------'
 41| s            | Delete a single character under the cursor and enter input |
 42|              | mode (equivalent to c[SPACE]).                             |
 43'--------------+------------------------------------------------------------'
 44| r            | Replaces a single character under the cursor (without      |
 45|              | leaving command mode).                                     |
 46'--------------+------------------------------------------------------------'
 47| R            | Replaces characters under cursor.                          |
 48'--------------+------------------------------------------------------------'
 49| v            | Edit (and execute) the current command in the text editor. |
 50|              | (an editor defined in $VISUAL or $EDITOR variables, or vi  |
 51'--------------'------------------------------------------------------------'
 52| Basic Movement Commands (in command mode):                                |
 53'--------------.------------------------------------------------------------'
 54| h            | Move one character right.                                  |
 55'--------------+------------------------------------------------------------'
 56| l            | Move one character left.                                   |
 57'--------------+------------------------------------------------------------'
 58| w            | Move one word or token right.                              |
 59'--------------+------------------------------------------------------------'
 60| b            | Move one word or token left.                               |
 61'--------------+------------------------------------------------------------'
 62| W            | Move one non-blank word right.                             |
 63'--------------+------------------------------------------------------------'
 64| B            | Move one non-blank word left.                              |
 65'--------------+------------------------------------------------------------'
 66| e            | Move to the end of the current word.                       |
 67'--------------+------------------------------------------------------------'
 68| E            | Move to the end of the current non-blank word.             |
 69'--------------+------------------------------------------------------------'
 70| 0            | Move to the beginning of line                              |
 71'--------------+------------------------------------------------------------'
 72| ^            | Move to the first non-blank character of line.             |
 73'--------------+------------------------------------------------------------'
 74| $            | Move to the end of line.                                   |
 75'--------------+------------------------------------------------------------'
 76| %            | Move to the corresponding opening/closing bracket.         |
 77'--------------'------------------------------------------------------------'
 78| Character Finding Commands (these are also Movement Commands):            |
 79'--------------.------------------------------------------------------------'
 80| fc           | Move right to the next occurance of char c.                |
 81'--------------+------------------------------------------------------------'
 82| Fc           | Move left to the previous occurance of c.                  |
 83'--------------+------------------------------------------------------------'
 84| tc           | Move right to the next occurance of c, then one char       |
 85|              | backward.                                                  |
 86'--------------+------------------------------------------------------------'
 87| Tc           | Move left to the previous occurance of c, then one char    |
 88|              | forward.                                                   |
 89'--------------+------------------------------------------------------------'
 90| ;            | Redo the last character finding command.                   |
 91'--------------+------------------------------------------------------------'
 92| ,            | Redo the last character finding command in opposite        |
 93|              | direction.                                                 |
 94'--------------+------------------------------------------------------------'
 95| |            | Move to the n-th column (you may specify the argument n by |
 96|              | typing it on number keys, for example, 20|)                |
 97'--------------'------------------------------------------------------------'
 98| Deletion Commands:                                                        |
 99'--------------.------------------------------------------------------------'
100| x            | Delete a single character under the cursor.                |
101'--------------+------------------------------------------------------------'
102| X            | Delete a character before the cursor.                      |
103'--------------+------------------------------------------------------------'
104| d<mov. comm> | Delete text of a movement command <mov. comm> (see above). |
105'--------------+------------------------------------------------------------'
106| D            | Delete to the end of the line (equivalent to d$).          |
107'--------------+------------------------------------------------------------'
108| dd           | Delete current line (equivalent to 0d$).                   |
109'--------------+------------------------------------------------------------'
110| CTRL-w       | Delete the previous word.                                  |
111'--------------+------------------------------------------------------------'
112| CTRL-u       | Delete from the cursor to the beginning of line.           |
113'--------------'------------------------------------------------------------'
114| Undo, Redo and Copy/Paste Commands:                                       |
115'--------------.------------------------------------------------------------'
116| u            | Undo previous text modification.                           |
117'--------------+------------------------------------------------------------'
118| U            | Undo all previous text modifications.                      |
119'--------------+------------------------------------------------------------'
120| .            | Redo the last text modification.                           |
121'--------------+------------------------------------------------------------'
122| y<mov. comm> | Yank a movement into buffer (copy).                        |
123'--------------+------------------------------------------------------------'
124| yy           | Yank the whole line.                                       |
125'--------------+------------------------------------------------------------'
126| p            | Insert the yanked text at the cursor.                      |
127'--------------+------------------------------------------------------------'
128| P            | Insert the yanked text before the cursor.                  |
129'--------------'------------------------------------------------------------'
130| Commands for Command History:                                             |
131'--------------.------------------------------------------------------------'
132| k            | Insert the yanked text before the cursor.                  |
133'--------------+------------------------------------------------------------'
134| j            | Insert the yanked text before the cursor.                  |
135'--------------+------------------------------------------------------------'
136| G            | Insert the yanked text before the cursor.                  |
137'--------------+------------------------------------------------------------'
138| /string or   | Search history backward for a command matching string.     |
139| CTRL-r       |                                                            |
140'--------------+------------------------------------------------------------'
141| ?string or   | Search history forward for a command matching string.      |
142| CTRL-s       | (Note that on most machines Ctrl-s STOPS the terminal      |
143|              | output, change it with `stty' (Ctrl-q to resume)).         |
144'--------------+------------------------------------------------------------'
145| n            | Repeat search in the same direction as previous.           |
146'--------------+------------------------------------------------------------'
147| N            | Repeat search in the opposite direction as previous.       |
148'--------------'------------------------------------------------------------'
149| Completion commands:                                                      |
150'--------------.------------------------------------------------------------'
151| TAB or = or  | List all possible completions.                             |
152| CTRL-i       |                                                            |
153'--------------+------------------------------------------------------------'
154| *            | Insert all possible completions.                           |
155'--------------'------------------------------------------------------------'
156| Miscellaneous commands:                                                   |
157'--------------.------------------------------------------------------------'
158| ~            | Invert case of the character under cursor and move a       |
159|              | character right.                                           |
160'--------------+------------------------------------------------------------'
161| #            | Prepend '#' (comment character) to the line and send it to |
162|              | the history.                                               |
163'--------------+------------------------------------------------------------'
164| _            | Inserts the n-th word of the previous command in the       |
165|              | current line.                                              |
166'--------------+------------------------------------------------------------'
167| 0, 1, 2, ... | Sets the numeric argument.                                 |
168'--------------+------------------------------------------------------------'
169| CTRL-v       | Insert a character literally (quoted insert).              |
170'--------------+------------------------------------------------------------'
171| CTRL-r       | Transpose (exchange) two characters.                       |
172'--------------'------------------------------------------------------------'
173
174
175 ===========================================================================
176
177.---------------------------------------------------------------------------.
178| Peteris Krumins ([email protected]), 2008.01.08.                         |
179| http://www.catonmat.net  -  good coders code, great reuse                 | 
180|                                                                           |
181| Released under the GNU Free Document License                              |
182'---------------------------------------------------------------------------'

The Definitive Guide to Bash Command Line History (ASCII .txt format)

テキストフォーマットは、以下に貼っておきます

  1.---------------------------------------------------------------------------.
  2|                                                                           |
  3|                          Bash History Cheat Sheet                         |
  4|                                                                           |
  5'---------------------------------------------------------------------------'
  6| Peteris Krumins ([email protected]), 2008.02.15                          |
  7| http://www.catonmat.net  -  good coders code, great reuse                 |
  8|                                                                           |
  9| Released under the GNU Free Document License                              |
 10'---------------------------------------------------------------------------'
 11
 12 ===================== Emacs Keyboard Shortcut Summary =====================
 13
 14.--------------.------------------------------------------------------------.
 15|              |                                                            |
 16| Shortcut     | Description                                                |
 17|              |                                                            |
 18'--------------+------------------------------------------------------------'
 19| C-p          | Fetch the previous command from the history list.          |
 20'--------------+------------------------------------------------------------'
 21| C-n          | Fetch the next command from the history list.              |
 22'--------------+------------------------------------------------------------'
 23| M-<          | Move to the first line in the history.                     | 
 24'--------------+------------------------------------------------------------'
 25| M->          | Move to the end of the input history.                      |
 26'--------------+------------------------------------------------------------'
 27| C-r          | Search backward starting at the current line (incremental) |
 28'--------------+------------------------------------------------------------'
 29| C-s          | Search forward starting at the current line (incremental). |
 30'--------------+------------------------------------------------------------'
 31| M-p          | Search backward using non-incremental search.              |
 32'--------------+------------------------------------------------------------'
 33| M-n          | Search forward using non-incremental search                |
 34'--------------'------------------------------------------------------------'
 35
 36 ======================= Vi Keyboard Shortcut Summary ======================
 37
 38.--------------.------------------------------------------------------------.
 39|              |                                                            |
 40| Shortcut     | Description                                                |
 41|              |                                                            |
 42'--------------+------------------------------------------------------------'
 43| k            | Fetch the previous command from the history list.          |
 44'--------------+------------------------------------------------------------'
 45| j            | Fetch the next command from the history list.              |
 46'--------------+------------------------------------------------------------'
 47| /string or   | Search history backward for a command matching string.     |
 48| CTRL-r       |                                                            |
 49'--------------+------------------------------------------------------------'
 50| ?string or   | Search history forward for a command matching string.      |
 51| CTRL-s       | (Note that on most machines Ctrl-s STOPS the terminal      |
 52|              | output, change it with `stty' (Ctrl-q to resume)).         |
 53'--------------+------------------------------------------------------------'
 54| n            | Repeat search in the same direction as previous.           |
 55'--------------+------------------------------------------------------------'
 56| N            | Repeat search in the opposite direction as previous.       |
 57'--------------+------------------------------------------------------------'
 58| G            | Move to history line N (for example, 15G).                 |
 59'--------------'------------------------------------------------------------'
 60
 61 ======================== History Expansion Summary ========================
 62 
 63 Event Designators:
 64
 65.--------------.------------------------------------------------------------.
 66|              |                                                            |
 67| Designator   | Description                                                |
 68|              |                                                            |
 69'--------------+------------------------------------------------------------'
 70| !            | Start a history substitution.                              |
 71'--------------+------------------------------------------------------------'
 72| !!           | Refer to the last command.                                 |
 73'--------------+------------------------------------------------------------'
 74| !n           | Refer to the n-th command line (try `history' command).    |
 75'--------------+------------------------------------------------------------'
 76| !-n          | Refer to the current command line minus n.                 |
 77'--------------+------------------------------------------------------------'
 78| !string      | Refer to the most recent command starting with 'string'.   |
 79'--------------+------------------------------------------------------------'
 80| !?string?    | Refer to the most recent command containing 'string'.      |
 81'--------------+------------------------------------------------------------'
 82| ^str1^str2^  | Quick substitution. Repeat the last command, replacing     |
 83|              | 'str1' with 'str2'.                                        |
 84'--------------+------------------------------------------------------------'
 85| !#           | Refer to the entire command line typed so far.             |
 86'--------------'------------------------------------------------------------'
 87
 88 Word Designators:
 89 (Word designators follow the event designators, separated by a collon ':')
 90
 91.--------------.------------------------------------------------------------.
 92|              |                                                            |
 93| Designator   | Description                                                |
 94|              |                                                            |
 95'--------------+------------------------------------------------------------'
 96| 0            | The zeroth (first) word in a line (usually command name).  |
 97'--------------+------------------------------------------------------------'
 98| n            | The n-th word in a line.                                   |
 99'--------------+------------------------------------------------------------'
100| ^            | The first argument (the second word) in a line.            |
101'--------------+------------------------------------------------------------'
102| $            | The last argument in a line.                               |
103'--------------+------------------------------------------------------------'
104| %            | The word matched by the most recent string search.         |
105'--------------+------------------------------------------------------------'
106| x-y          | A range of words from x to y (-y is synonymous with 0-y).  |
107'--------------+------------------------------------------------------------'
108| *            | All words but the zeroth (synonymous with 1-$).            |
109'--------------+------------------------------------------------------------'
110| x*           | Synonymous with x-$                                        |
111'--------------+------------------------------------------------------------'
112| x-           | The words from x to the second to last word.               |
113'--------------'------------------------------------------------------------'
114
115 Modifiers (modifiers follow word designators, separated by a colon):
116
117.--------------.------------------------------------------------------------.
118|              |                                                            |
119| Modifier     | Description                                                |
120|              |                                                            |
121'--------------+------------------------------------------------------------'
122| h            | Remove a trailing pathname component, leaving the head.    |
123'--------------+------------------------------------------------------------'
124| t            | Remove all leading pathname component, leaving the tail.   |
125'--------------+------------------------------------------------------------'
126| r            | Remove a trailing suffix of the form .xxx, leaving the     |
127|              | basename.                                                  |
128'--------------+------------------------------------------------------------'
129| e            | Remove all but the trailing suffix.                        |
130'--------------+------------------------------------------------------------'
131| p            | Print the resulting command but do not execute it.         |
132'--------------+------------------------------------------------------------'
133| q            | Quotes the substituted words, escaping further             |
134|              | substitutions.                                             |
135'--------------+------------------------------------------------------------'
136| x            | Quotes the substituted words, breaking them into words at  |
137|              | blanks and newlines.                                       |
138'--------------+------------------------------------------------------------'
139| s/old/new/   | Substitutes 'new' for 'old'.                               |
140'--------------+------------------------------------------------------------'
141| &            | Repeats the previous substitution.                         |
142'--------------+------------------------------------------------------------'
143| g            | Causes s/old/new/ or & to be applied over the entire       |
144|              | event line.                                                |
145'--------------'------------------------------------------------------------'
146
147 ============ History Behavior Modification via Shell Variables ============
148
149.----------------.----------------------------------------------------------.
150|                |                                                          |
151| Shell Variable | Description                                              |
152|                |                                                          |
153'----------------+----------------------------------------------------------'
154| HISTFILE       | Controls where the history file gets saved.              |
155|                | Set to /dev/null not to save the history.                |
156|                | Default: ~/.bash_history                                 |
157'----------------+----------------------------------------------------------'
158| HISTFILESIZE   | Controls how many history commands to keep in HISTFILE   |
159|                | Default: 500                                             |
160'----------------+----------------------------------------------------------'
161| HISTSIZE       | Controls how many history commands to keep in the        |
162|                | history list of current session.                         |
163|                | Default: 500                                             |
164'----------------+----------------------------------------------------------'
165| HISTIGNORE     | Controls which commands to ignore and not save to the    |
166|                | history list. The variable takes a list of               |
167|                | colon separated values. Pattern & matches the previous   |
168|                | history command.                                         |
169'----------------'----------------------------------------------------------'
170
171 ============ History Behavior Modification via `shopt' Command ============
172
173.----------------.----------------------------------------------------------.
174|                |                                                          |
175| shopt Option   | Description                                              |
176|                |                                                          |
177'----------------+----------------------------------------------------------'
178| histappend     | Setting the variable appends current session history to  |
179|                | HISTFILE. Unsetting overwrites the file each time.       |
180'----------------+----------------------------------------------------------'
181| histreedit     | If set, puts a failed history substitution back on the   |
182|                | command line for re-editing.                             |
183'----------------+----------------------------------------------------------'
184| histverify     | If set, puts the command to be executed after a          |
185|                | substitution on command line as if you had typed it.     |
186'----------------'----------------------------------------------------------'
187
188 shopt options can be set by a `shopt -s option' and
189 can be unset by             a `shopt -u option'.
190
191 =============================== Examples ==================================
192
193 $ echo a b c d e    (executes `echo ab c d e`)
194 a b c d e
195
196 $ echo !!:3-$       (executes `echo c d e`)
197 c d e
198
199 $ echo !-2:*:q      (executes `echo 'a b c d e'`)
200 a b c d e
201
202 $ echo !-3:1:2:4:x  (executes `echo 'a' 'b' 'd'`)
203 a b d
204
205 $ echo !-4:1-3:s/a/foo/:s/b/bar/:s/c/baz/ (executes `echo foo bar baz`)
206 foo bar baz
207
208 $ tar -xzf package-x.y.z.tgz
209 ...
210 $ cd !-1:$:r        (executes `cd package-x.y.z`)
211 package-x.y.z $
212 
213 $ ls -a /tmp
214 file1  file2  file3 ...
215
216 $ ^-a^-l^           (executes `ls -l /tmp`)
217 -rw-------  1  user  user  file1
218 ...
219
220 ===========================================================================
221
222.---------------------------------------------------------------------------.
223| Peteris Krumins ([email protected]), 2008.02.15                          |
224| http://www.catonmat.net  -  good coders code, great reuse                 | 
225|                                                                           |
226| Released under the GNU Free Document License                              |
227'---------------------------------------------------------------------------'
Tags:
comments powered by Disqus