25

In vi, I have mapped 'jj' to escape to be able to switch to command mode without using the annoying escape key. Now I want to have the same for command line editing for which I use vi-mode. I already have found the following solution:

bindkey '^j' vi-cmd-mode

lets you change with control-j into command mode. Still searching for a solution without modifier-keys as 'jj' or something similar.

2
  • 4
    Why not just remapping Caps Lock to Escape?
    – remmy
    Jan 12, 2013 at 21:34
  • I can't use the escape key because iTerm needs it for sending meta :( May 18, 2022 at 4:36

1 Answer 1

39

Note: You should look at man zshzle for a lot of goodies about customizing bindkey and emulating GNU readline.

This is how I mapped jj to Esc:

bindkey -M viins 'jj' vi-cmd-mode

If you're interested in distinguishing between insert-mode and normal-mode, you could try out the suggestion akira mentions here

4
  • yeah! works perfectly. thx alot!
    – Eman Resu
    Nov 6, 2011 at 13:17
  • Are there any prerequisites that need to be fulfilled before this works in zsh? Or ways to debug the key bindings? After inserting this command, nothing happens. jj still doesn't work. Aug 25, 2014 at 4:12
  • 7
    I had KEYTIMEOUT set too low, that was the reason. Aug 25, 2014 at 4:16
  • 2
    @Ultramaster makes a great point. If you're already setting the KEYTIMEOUT for speed, I'd recommend >= 20 milliseconds. Such as export KEYTIMEOUT=20
    – craft
    Dec 25, 2018 at 14:59

You must log in to answer this question.

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