Question 7 which bash shortcut or command jumps to the beginning of the command line?

Improve Article

Save Article

  • Read
  • Discuss
  • Improve Article

    Save Article

    In this article, we will learn how to move to the start and end of a command. We will demonstrate the key combinations in a Git terminal. The same key combinations work in other Unix style terminals too.

    Moving to the Starting of the Command

    Ctrl + A : The ‘Ctrl+A’ key combination moves the pointer to the start of the command. In the below gif image, you can see how pressing the ‘ctrl+A‘ combination after typing the command ‘touch index.html‘ moved the pointer to the start.

    Question 7 which bash shortcut or command jumps to the beginning of the command line?

    Moving to the Ending of the Command

    Ctrl + E : The ‘Ctrl+E’ key combination moves the pointer to the end of the command. In the below gif image, you can see how pressing the ‘ctrl+E’ combination moves the pointer to the end i.e., at the end of ‘touch app.js‘.

    Question 7 which bash shortcut or command jumps to the beginning of the command line?

    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 *

    Which bash shortcut or command jumps to the beginning of the command line?

    These shortcuts will help: Ctrl + E - go to the end of the line. Ctrl + A - go to the start of the line. Alt + left - go back one word.

    Which bash shortcut or command copies the last argument of previous commands?

    I often use the Bash command yank-last-arg , shortcut M-. or Esc + . . This copies the last argument from the previous history entry into the current line at the current position, so you can check and edit the argument.

    Which bash shortcut for command displays the list of previous commands?

    The following shortcuts are used for searching for commands in the bash history:.
    Up arrow key – retrieves the previous command. ... .
    Ctrl+P and Ctrl+N – alternatives for the Up and Down arrow keys, respectively..

    Which bash shortcut or command is used to clear characters from the cursor to the end of the command line?

    Ctrl + A Ctrl + K - move the cursor at the beginning of the line and clear all the current line from the beginning to the end.