Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
share|improve this question
Running bind -p should tell you what keyboard commands exist. – choroba Nov 10 '12 at 15:46
up vote 1 down vote accepted

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.

share|improve this answer
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. – user495470 Nov 17 '12 at 9:31

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

share|improve this answer
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
@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 posting your answer, you agree to the privacy policy and terms of service.

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