For example, if I hit the right combination of keys to enter viins and walk away from the terminal and forget, how can I tell when I get back? How can I tell what the default mode is? The guide has this:

If you’re in the wrong mode, ‘bindkey -e’ in ~/.zshrc takes you to emacs mode and ‘bindkey -v’ to vi mode.

But what is the mode? I'd like to know before typing. The $KEYMAP special variable is, as far as I can see, only available within zle widgets, and I can find nothing in man zshzle nor the zshell user guide as to how to tell what the current mode is.

Any help or insight will be much appreciated.


1 Answer 1


TL;DR: do a bindkey -lL main and you'll see the name of the keymap before the word main.

From my reading of the docs it seems that the "current" keymap is denoted by the name main. This is typically aliased to either the viins or emacs keymap.

Further down it states:

-l                (lowercase ‘L’)

List all existing keymap names; if any arguments are given, list just those keymaps.

If the -L option is also used, list in the form of bindkey commands to create or link the keymaps.  ‘bindkey -lL main’ shows which keymap is linked to ‘main’, if any, and hence if the standard emacs or vi emulation is in effect.  This option does not show the .safe keymap because it cannot be created in that fashion; however, neither is ‘bindkey -lL .safe’ reported as an error, it simply outputs nothing.

So, if you do a bindkey -lL you'll see that (in normal circumstances) one of the keymaps is aliased (via bindkey -A) to main which is the "current" keymap.

If the main keymap doesn't exist, you are dropped into the .safe keymap, which is very unfriendly but will function well enough for you to fix things.  If this happens to you, bindkey -d should reset your keymap situation.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .