Why is the shortcut Ctrl + A jumping to the start of a line in the terminal?

There are two sides to the question, the technical side and the historical side.

The technical answer is because bash uses GNU Readline. In readline Control-a is bound to the function beginning-of-line, you can show this with:

$ bind -q beginning-of-line
beginning-of-line can be invoked via "\C-a", "\M-OH", "\M-[1~", "\M-[7~", "\M-[H".

where \C-a means "Control-a". bind -p will show all bindings (be careful using bind, it's easy to break your keyboard if you accidentally provide additional options or arguments).

Some of the above bindings are added by default, others I have added (via .inputrc) for various terminals I have used. Since bash-2.0, if the terminal termcap contains the capabilities kh, and kH then Home and End will be set to beginning-of-line and end-of-line. Both bash and readline are developed by Chet Ramey, an Emacs user and also the developer of ce an Emacs clone.


(Please note, this endeavours to summarise many years of history from many decades ago, and glosses over some details.)

Now, why is it Control-a in particular? Readline uses by default Emacs-like bindings. Control-a in GNU Emacs invokes move-beginning-of-line, what we consider to be the "home" function now.

Stallman and Steel's original EMACS was inspired by Fred Wright's E editor (an early WYSIWYG editor) and TECO (a cryptic modal editor/language) -- EMACS was a set of macros for TECO. See Essential E [PDF] (from SAIL, 1980). E however used Control-Form for "beginning of line", this was on the "DataDisc" keyboard which had a Control key, and a Form key. The space-cadet keyboard of the time (lacking a Home key by the way, though it had an End) is commonly blamed for the Emacs keyboard interface.

One of the desirable features of EMACS was its use of TECO's Control-R "real-time" line editing mode (TECO predates CRT/keyboard terminals), you can see the key bindings on page 6 of the MIT AI Lab 1978 ITS Introduction to the EMACS editor [scanned PDF], where ┌ is used to denote Control. In this mode, the key bindings were all control sequences, largely mnemonic: Control-E End of this line, Control-P move to previous line, Control-N move to next line, Control-B backward one character, and not least Control-A move to beginning of this line, Costas' suggestion of "first letter of the alphabet" for this is as good as any.

(A similar key-binding is in the tvlib macro package which aimed to make EMACS behave like the TVEDIT editor, binding control A and E to backward and forward sentence, but used different sequences for beginning and end of line.)

The Control-A/Control-E bindings in "^R mode" were implemented directly in the ITS TECO (1983, version 1208, see the _teco_.tgz archive at the nocrew PDP10/ITS site, or on Github ), though I cannot determine more accurately when they first appeared, and the TECO source doesn't indicate why any particular bindings were chosen. The 1978 MIT EMACS document above implies that in 1978 EMACS did not use TECO native Control-A/Control-E, it's possible that the scrlin macro package (screen line) implemented these.

To recap:

  • bash uses readline
  • readline key bindings follow Emacs/EMACS
  • the original EMACS was created with TECO, inheriting many features
  • TECO's interactive mode macros used (mostly) mnemonic control key bindings, and "start of line" ended up assigned to Control-A

See also:

  • http://www.gnu.org/gnu/rms-lisp.html
  • http://xahlee.info/kbd/keyboard_hardware_and_key_choices.html
  • http://blog.djmnet.org/2008/08/05/origin-of-emacs/
  • http://www.jwz.org/doc/emacs-timeline.html
  • http://www.multicians.org/mepap.html *

Because Richard Stallman likes Emacs.

Ctrl+a is jumping to the start of the line in Emacs, and libreadline uses the same key bindings as Emacs. Bash uses libreadline.