Is there a way to jump to an earlier part of a command line command in the Mac Terminal?

I'll often find myself writing out long commands in the bash shell - things with many arguments, web addresses, routes, etc and so on. Every so often I will realize I forgot to, say, put my "bundle exec" at the beginning of the command, or misspelled something, or forgot quotes. Or something as simply as putting "cd" instead of "vim".

Thus begins the tedious process of holding the left arrow key until I get back to the beginning of the command.

Is there an any way to jump to the beginning of the line again?


Solution 1:

In addition to ^A and ^E, you can do

  • Esc-b to jump back one word
  • Esc-f to jump forward one word
  • Ctrl-b to move back one character
  • Ctrl-f to move forward one character

See the bash manual for commands for moving.

Solution 2:

You can use Emacs commands, e.g.:

  • ctrl-A to go to the beginning of the command line
  • ctrl-E to go to the end of the command line

This is bash, not specific to Mac.

Solution 3:

set -o vi

Then Esc followed by

^ start of line $ end of line b one word backword w one word forward