11

How would I map jj to Esc in zsh?

I'm trying to recreate a key-mapping that I have setup in vim, where I have jj mapped to ESC so that whenever I double-press j, it sends the an <Esc> to vim--allowing me to enter normal mode with greater convenience.

I've already tried bindkey 'jj' ^[, and I'm about to try bindkey 'jj' ^[[, but I doubt that it'll work. I also checked the list of commands provided by zsh in normal mode, but I didn't see anything that contained normal or escape.

NOTE
The ^[ characters in my ~/.zshrc file are actual hard coded escapes; not just the characters ^ and [.

11

You need -s to bind actual strings instead of widgets:

bindkey -s jj '\e'

Though you probably want to map jj to the vi-cmd-mode widget here:

bindkey jj vi-cmd-mode

(note that's for binding in insert mode, not normal/command mode)

  • 1
    the second one works like a charm, thanks! – Alexej Magura Nov 14 '13 at 23:50
  • 2
    NOTE setting KEYTIMEOUT seems to break the key-binding. – Alexej Magura Dec 27 '13 at 19:28
  • @AlexejMagura just adding: setting KEYTIMEOUT too low prohibits zle from recognizing double press. – UltraMaster Aug 25 '14 at 4:22

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.