I am trying to figure out a few keyboard shortcuts in a terminal in Mac OS X (and Linux):

In the command line:

  1. go to the next word
  2. go to the previous word
  3. go to the end of the line
  4. go to the beginning of the line

This will make it easier to change commands. Right now, I am using the left/right arrow keys, which is time consuming.

EDIT: I used bind -p as suggested below. What do the following key bindings mean?

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


"\e\e[C": forward-word
"\e[1;5C": forward-word
"\e[5C": forward-word
"\ef": forward-word
  • Running bind -p should tell you what keyboard commands exist. – choroba Nov 10 '12 at 15:46

You're looking for the readline movement commands. They are shared with emacs. Here are the defaults:

  • Ctrl+A: start of line
  • Ctrl+E: end of line
  • Alt+F: forward a word
  • Alt+B: backward a word

You might also have Alt+ and Alt+ keys bound for back and forward a word. My OSX 10.6 doesn't, but my Ubuntu 12.04 does.

Note that in OSX you can't use alt by default since that puts in an accented letter. Rather, use escape. You have to hit it each time though, you can't hold it down.

The other answer referring to vi-mode may also be useful to you if you are familiar with vi. See here for some more info.

  • also usefull Ctrl-w - delete prev word, – zb' Nov 10 '12 at 17:22
  • alt-f and alt-b don't work for me here... any ideas? – kloop Nov 10 '12 at 19:00
  • read the above answer, carefully. works fine on Linux debian – wuxmedia Nov 10 '12 at 20:22
  • As @wuxmedia said, read carefully. Alt doesn't work normally on OSX. – ssmy Nov 11 '12 at 18:40
  • You can use ⌥B and ⌥F in Terminal if you check Settings > Keyboard > Use option as meta key. – Lri Nov 17 '12 at 9:31

If you're using VI mode command-line editing, then you would use (in order) w b $ 0

  • I am not talking about vi, but regular command-line in the terminal, or did you mean something else? – kloop Nov 10 '12 at 15:52
  • 1
    @kloop Some shells have a vi mode; try set -o vi and see if the input now behaves like that most delicious of editors. – Kazark Nov 10 '12 at 18:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.