13

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 [.

0

1 Answer 1

15

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)

5
  • 1
    the second one works like a charm, thanks! Commented Nov 14, 2013 at 23:50
  • 3
    NOTE setting KEYTIMEOUT seems to break the key-binding. Commented Dec 27, 2013 at 19:28
  • 1
    @AlexejMagura just adding: setting KEYTIMEOUT too low prohibits zle from recognizing double press. Commented Aug 25, 2014 at 4:22
  • @AlexejMagura , What should be the KEYTIMEOUT ?
    – Jdeep
    Commented Oct 24, 2020 at 19:14
  • @Jdeep, export KEYTIMEOUT=10
    – Good Pen
    Commented Apr 11, 2023 at 11:23

You must log in to answer this question.

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