4

On some Unix systems, I can type Ctrl-A or Ctrl-E to move to the beginning or end of the line. On some Unix systems I can not and it just prints ^A or ^E, etc. What controls whether this keystoke works as I expect (move around the command line), or prints the ^A, ^E, etc. character?

7

It all depends on specific shell implementation (you might have different default shell on different systems or even for different users within a single system, e.g. bash, ksh, tcsh, etc).

Also it depends on shell itself.

E.g. bash supports two modes: emacs and vi. Each mode has its own shortcuts (emacs or vi like). To change it you have to execute set -o emacs (normally it's a default one) or set -o vi

You can find more information in your specific shell documentation.

7

tl;dr

set -o emacs

will enable the Ctrl-A, Ctrl-E, Ctrl-B, etc emacs key bindings in most shells you're likely to use.


The shell may not have any line editing capabilities, or may be in the vi editing mode (the only one specified by the standard).

When not in emacs editing mode, the Ctrl-A and Ctrl-E have no special significance. If the echo and echoctl stty/termios setting are on, all control keys which are not handled specially will be displayed in the ^A, ^X, etc, "caret" notation.

Many shells (like ksh or zsh) will determine the default editing mode (vi or emacs) based on the values of VISUAL and EDITOR environment variables (in this order of precedence, and also handling variants like vim, elvis, xemacs, etc).

This was broken (very annoyingly!) in mksh, but it's also still the case in other pdksh-derived shells.

Other shells like bash or tcsh default to the emacs editing mode, but that may also be overridden from the configuration file of the line editing library.

For the readline library used by bash and many other programs, the configuration files is ~/.inputrc (or a file specified in the INPUTRC environment variable) with a fallback to /etc/inputrc and the settings are:

set editing-mode vi
set editing-mode emacs

For the editline/libedit[1] library used by many BSD programs, the configuration file is usually ~/.editrc and the settings are:

bind -v  # for vi
bind -e  # for emacs

[1] not to be confused with the libeditline readline "work-alike" which only provides an emacs editing-mode.

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.