2

From what I have seen, both set -o emacs and bindkey -e are used to modify the behavior of your terminal line editor to emulate emacs whereas set -o vi and bindkey -v are used to emulate vi keybindings. Since both set -o and bindkey seem to do the same thing, I was wondering what the differences between the two were and if there were any differences at all.

It seems like set -o works for most shells whereas bindkey is a zle specific command. Is this the only difference? Also, do they bind the same keys or are there some keys where set -o and bindkey bind to different operations?

0

1 Answer 1

4

bindkey -v/-e is the tcsh syntax (a bindkey builtin was added to tcsh in 5.19PL2 in 1990), while set -o vi/emacs is the ksh syntax (already there in ksh85, probably earlier as ksh had emacs/vi mode at least as far back as 1983).

In zsh, bindkey was added in 2.0 in 1991 which came with the first version of zle (1.0 the previous version used readline borrowed from bash).

zsh, since the first 1.0 version had setopt to set options (in addition to the options passed on the command line like in csh/Bourne), while (t)csh and bash used special variables instead. In 2.0, a -o option (both to the interpreter and to the set builtin) was added for compatibility with ksh (bash itself converted its special variables to options set with a new shopt builtin in 2.0 in 1996; that's a separate set of options from those set with set -o there; set -o support added circa 1990).

The vi and emacs "options" were not added to zsh until 2003 in version 4.1.1 though. The "option" paradigm is not very appropriate for that as when you set the emacs option, it disables the vi mode.

You'll notice that zsh -o emacs and zsh -o vi currently don't work properly in that zsh reports zsh: invalid module name `zsh/zle' on startup (a bug).

Most shells including zsh also select the default editing mode based on the value of the $EDITOR and $VISUAL environment variables to try and match the line editing mode to the user's editor preference.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.