In Bash shell, when editting in the command line. There are two different modes, vi mode or Emacs mode. Emacs-mode is the default mode. Below are some of the handy shortcuts in Emacs-mode.

  • ALT-b and ALT-f: go backward(toward begining of the line)/forward (toward end of the line) a word. Note that - is a word separator in this case.
  • Ctrl-A and Ctrl-E: go to begining/end of the line.
  • Ctrl-K and Ctrl-U: delete till the end/begining of the line.
  • Ctrl-R: search history command. Press Enter to run a command, or press movement key to edit it.
  • ALT-D: Delete from current cursor position to the end of the word.
  • Ctrl-_: Undo edit.
  • ALT-R: Revert command to original.
  • Ctrl-W: Delete a word backward. Note that here word is separate by space. So if we have python util/| (| indicate cursor) , pressing Ctrl-W leave us with only python . - is not a word separator in this case. A little inconsistent, IMHO.