Like several other popular shells, zsh offers two command line editing modes: Emacs-like (modeless) and Vi-like (with insert and command modes). Unlike other popular shells, zsh starts up in Vi-like mode if the environment variable VISUAL
or EDITOR
contains vi
when zsh starts up.
You're setting the environment variable EDITOR
in your .zshrc
. When you open a terminal and the terminal emulator program starts zsh, EDITOR
is not set, so zsh starts in Emacs mode. When you start a tmux session from inside that shell, EDITOR
is set to a string containing vi
in the environment of tmux, and so it's already set when zsh starts in a tmux window. So, inside tmux windows, zsh runs in Vi-like mode.
In Vi-like operating mode, there are two editing modes: insert and command. Each has its own key bindings, and bindkey
with no option only applies to insert mode. So your custom bindings don't work in command mode, i.e. after pressing Escape. Most default bindings don't work either.
To avoid this, since you don't appear to want Vi-like mode, explicitly select Emacs-like mode by putting the following command before any other call to bindkey
in your .zshrc
:
bindkey -e
The real problem is that you're setting EDITOR
in the wrong place. Generally speaking, don't set environment variables in shell initialization files (.bashrc
, .zshrc
), because they only take effect in programs that run from that shell. A program started directly from a GUI launcher won't inherit those variables, and so won't call your preferred editor. Instead, set environment variables in a file that is read when your login session starts, such as ~/.profile
(for classical Unix-like sessions, including most X11-based setups).
.zshrc
(please reduce it to a small file that reproduces the problem) and knowing which key(s) are problematic. Also post the difference in the output ofbindkey
inside and outside tmux, if there's any difference.