Friday, October 31, 2008

bash shortkeys

(C = control key, M = alt/meta key.)

  1. C-r and C-s : Launch an incremental search backward and forward (respectively), in your command-line history.
  2. C-j and C-g : Abandon an incremental search either with the line found, or with the original line (respectively).
  3. M-. or ESC then . : Both of these insert the final argument to the last command at the cursor point. This is useful when moving files around and editing them.
  4. M-C-y : Insert the first argument to the previous command at the cursor point. If you want the nth argument, hit M-n beforehand. So M-2 M-C-y would give you the 2nd argument to the previous command. (A lot of keys to remember, but it's useful once in a while.)

  5. C-w and M-backspace : Both delete the word behind the cursor. C-w uses whitespace as a boundary, whereas M-backspace uses non-alphanumeric characters. So if you have file.txt and hit C-w, you'll delete the lot, whereas M-backspace would leave you with file.. This has very obvious uses. (It also works with underscores.)