Bash: How do I move my cursor to the left a word-at-a-time?

To set the key binding: You first have to find out what key codes the Ctrl+Left key sequence creates. Just use the command cat to switch off any interference with existing key bindings, and then type the key sequence. In my system (Linux), this looks like that:

$ cat
^[[1;5D

Press Ctrl+d to exit cat. Now you have found out that Ctrl-Left issues 6 key codes:

  • Escape (^[)
  • [
  • 1
  • ;
  • 5
  • D

Now you can issue the bind command:

bind '"\e[1;5D": backward-word'

The bash function you want is backward-word. You can run bind -q backward-word to get a list of keys bound to that function. One common binding is Esc+b

Also, many terminals support Ctrl+Left (the same hotkey you can use in X to jump backwards by word)


The default key shortcut in Bash for backword-word is Alt + b . The same result can be achived with Esc + b . You should give those a try before editing your keybindings.

Use bind command to edit or bind -q [name] to get the current keybind of a specific action.