1

In bash (4.3.11(1)-release), I want to be able to change straight from emacs keymap to the vi-command keymap.

With show-mode-in-prompt on, my prefix character should change from @ to :.

If I use the vi-movement-mode command, the prompt stays as @.

If I use the vi-editing-mode command, the prompt changes to + indicating I'm using the vi-insert keymap, rather than the desired target vi-command.

How do I change from emacs to vi-command keymaps via a binding?

Tom Hale
  • 28,728
  • 32
  • 139
  • 229

1 Answers1

4

The following .inputrc lines allow Meta / Alt+E to toggle between emacs and vi-insert modes.

Mooshing both j and k simultaneously will take you to vi-command mode.

set show-mode-in-prompt on

set keymap emacs
"\ee": vi-editing-mode
"jk": "\eejk"
"kj": "\eejk"

set keymap vi-insert
"\ee": emacs-editing-mode
"jk": vi-movement-mode
"kj": vi-movement-mode

set keymap vi-command
"\ee": emacs-editing-mode

Note: The only English word with "kj" is "blackjack", no words contain "jk")

Note: In bash v4.3.11(1), if you add a binding under keymap emacs to vi-movement-mode to try to switch straight to the vi-command keymap, the prompt doesn't update if you have show-mode-in-prompt on, hence this work-around is needed.

Tom Hale
  • 28,728
  • 32
  • 139
  • 229