Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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 than vim 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.

share|improve this question

1 Answer 1

up vote 19 down vote accepted

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.

share|improve this answer
    
Interesting. Is there any reason to use bindkey over set -o? –  zenith Apr 22 at 11:15
    
@zenith, probably not. bindkey is the tcsh way and original way. Nowadays they should be equivalent. –  Stéphane Chazelas Apr 22 at 11:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.