32

How can I map jj to Esc in inputrc so it gets picked up by apps using GNU Readline (python, mongoshell, ...)

all works fine on zsh using:

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

this is my current inputrc:

set editing-mode vi
set keymap vi

# turn off the stupid bell
set bell-style none
$if mode=vi
    set keymap vi-command
    "gg": beginning-of-history
    "G": end-of-history
    #"jj": vi-movement-mode
    set keymap vi-insert
    "\C-w": backward-kill-word
    "\C-p": history-search-backward
$endif
Ehtesh Choudhury
  • 7,452
  • 5
  • 42
  • 48
jassinm
  • 7,323
  • 3
  • 33
  • 42

1 Answers1

30

You should rearrange the inputrc so the commented line comes after set keymap vi-insert.

Like this:

set bell-style none
$if mode=vi
    set keymap vi-command
    "gg": beginning-of-history
    "G": end-of-history
    set keymap vi-insert       #notice how the "jj" movement is
    "jj": vi-movement-mode     #after 'set keymap vi-insert'?
    "\C-w": backward-kill-word
    "\C-p": history-search-backward
$endif
Ehtesh Choudhury
  • 7,452
  • 5
  • 42
  • 48
  • 2
    To show what applies to insert mode and what applies to command mode, refer to this answer: http://superuser.com/questions/286781/readline-difference-between-vi-vi-move-vi-command-vi-insert-keymaps – Michael Scheper Jul 26 '13 at 08:14
  • Is it possible to do something like this for ? I'm used to using that in vim and it would be nice to have it exit insert mode rather than going to the next line. Preferably without changing control-c functionality when a process is running. (I'm currently using bash btw) – mrfred Mar 19 '16 at 12:40