I am on macOS/darwin using a "default settings" zsh environment (no "oh-my-zsh" or any of that).

Some developer tool I just installed apparently broke some keybinds that I use frequently -- the emacs-style control-a and control-e "beginning-of-line" and "end-of-line" cursor movements. When I type control-a, the ^A token is inserted at the prompt. Only my user account on the system is affected -- a brand new user account on the same system is unaffected, in that the keyboard shortcuts work without any additional configuration.

Comparing the affected and unaffected environments, the output of bindkey differs. In the affected environment, bindkey outputs 49 lines, but in the unaffected environment, bindkey outputs 120 lines. It seems clear to me this is the source of the problem, but not the root cause.

Further investigation: on the affected shell, $ bindkey -lL returns:

bindkey -N command
bindkey -N emacs
bindkey -N isearch
bindkey -A viins main
bindkey -N vicmd
bindkey -N viins
bindkey -N viopp
bindkey -N visual

On the unaffected shell, this is identitcal except that line 4 is:

bindkey -A emacs main

This seems to make sense with the behavior I'm seeing -- the emacs-style binds I am expecting have been replaced with a different style of binds.

I still don't really know how bindkey works, so I am curious if it has some state somewhere on the system that I can inspect, or whether this is happening as the result of shell initialization files. The latter would be confusing, since I am only aware of ~/.zshenv and ~/.zshrc in my user profile that would affect only my shell context, and I believe I have controlled for this already. (Is there any way to list all of the initialization files that were sourced when loading the shell?)

Ultimately I would like to figure out what caused this behavior, so I can submit a bug report to the developer tool I installed that caused the issue.

2 Answers 2


bindkey -A … main defines what the main keymap is. The main keymap is the one that the editor uses each time you start editing a line. So what's changed is that the main keymap is now viins rather than emacs. Basically, zsh now uses Vi editing mode by default rather than Emacs editing mode.

Unless overridden in your .zshrc, zsh defaults to Vi editing mode if it thinks your favorite editor is Vi, and to Emacs editing mode otherwise. More precisely, “it thinks your favorite editor is Vi” is defined as

If one of the VISUAL or EDITOR environment variables contain the string ‘vi

It seems that something is now setting one or both of these variables. To fix the problem:

  • If you do want that editor with vi in its name to be your default editor, add bindkey -e (or bindkey -A emacs main) to your .zshrc to tell zsh that whatever it may think, you prefer Emacs editing mode in zsh.
  • If you don't want that default editor, figure out where the environment variable is set and remove this setting.

It appears that the tool you installed changed your main keymap from emacs to viins (by doing bindkey -v). To change main back to the default value of emacs, do

bindkey -e


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.