Why does exporting vim as EDITOR in zsh disable keyboard shortcuts?
zsh
like most modern shells have a choice between two different keyboard mappings for command-line editing: a vi
one and an emacs
one. In some shells (like tcsh
or readline
-based ones like bash
), the emacs
one is the default and probably the one you expect.
With zsh
, you get emacs
mode by default unless $EDITOR
or $VISUAL
contains vi
(if you're a vi
/nvi
/vim
/elvis
user (though also vimacs
and if $EDITOR
is /home/victor/bin/emacs
...), zsh
assumes you prefer the vi
mode).
To force a particular mode regardless of the value of $EDITOR
, add:
bindkey -e # for emacs
bindkey -v # for vi
or their more portable equivalent:
set -o emacs
set -o vi
to your ~/.zshrc
. See
info -f zsh -n Keymaps
for details.
Related videos on Youtube
![zenith](https://i.stack.imgur.com/uxg8z.gif?s=256&g=1)
zenith
Currently working on a new programming language intended as an alternative to C++. Other interests: electronic music production, DJing, conlanging.
Updated on September 18, 2022Comments
-
zenith almost 2 years
My
.zshrc
looks like this:export EDITOR="/usr/bin/vim"
Now when I open a terminal and enter a keyboard shortcut like ctrla to go to the beginning of the line, it doesn't work. Instead, the string
^A
(or some other string, depending on the shortcut I entered) gets entered to the terminal:emlai:~ % ^A
Removing the word
export
from my.zshrc
makes the keyboard shortcuts work properly:EDITOR="/usr/bin/vim"
Exporting
EDITOR
as something else thanvim
makes the keyboard shortcuts work too, e.g.:export EDITOR="/usr/bin/nano"
Why does this happen?
I tested this with
bash
as well, and the keyboard shortcuts work properly in all cases there. -
zenith about 9 yearsInteresting. Is there any reason to use
bindkey
overset -o
?