What's the meaning of the "set -o emacs" command?

What's the meaning, or what does the following do?

set -o emacs 

I saw it somewhere, and I am an Emacs user, so it makes me curious.


Solution 1:

set -o emacs tells the shell to understand Emacs editing commands.

That is, you can use Emacs commands at your shell prompt and they will work as expected. For example:

  • CtrlK deletes a line.
  • CtrlT transposes two chars.
  • MetaP deletes a word.
  • CtrlP goes to the previous line, that is, the previous command.

(More commands here, note that not all will work because not all make sense at the command line.)

set -o emacs works with bash, ksh and zsh, the default shell starting with macOS 10.15 Catalina. Other Bourne-based shells may include this functionality, too.

For bash and zsh, emacs is the default editing mode. You can also choose vi mode with set -o vi (in this case, you will probably want to set Option as the Meta key in the Keyboard tab of your Terminal profile).