I want a hybrid mode where I can use all the default keymap emacs key bindings by default, and still have the ability to change to vi-command mode.How do I set this up?
How can I setup a hybrid readline with emacs insert mode and vi command mode?
shell;readline
The following .inputrc lines allow Meta / Alt+E to switch between emacs and vi-insert modes.Mooshing both j and k simultaneously will take you to vi-command mode.Note: The only English word with kj is blackjack, no words contain jk)set show-mode-in-prompt onset keymap emacs\ee: vi-editing-modejk: \eejkkj: \eejkset keymap vi-insert\ee: emacs-editing-modejk: vi-movement-modekj: vi-movement-modeset keymap vi-command\ee: emacs-editing-modeNote: 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.Interesting factoids:There are only 4 bindings unique to vi-insert mode, which can be easily added to emacs mode:\C-d: vi-eof-maybe\C-n: menu-complete\C-p: menu-complete-backward\e: vi-movement-modeHowever note that the following are the default emacs bindings:\C-d: delete-char\C-n: next-history\C-p: previous-historyWhich I resolved as follows:set keymap emacs\e: kj # needs to be below kj mapping\C-d: delete-char # eof-maybe: ^D does nothing if there is text on the line\C-n: menu-complete\C-p: menu-complete-backward\C-y: previous-history # historY\e\C-y: previous-historyOld answerThis is how I did it before I could go directly from emacs to vi-command. It involves importing all the default emacs commands into the vi-insert keymap.Get the default emacs-standard and vi-insert mappings:INPUTRC=~/dev/null bash -c 'bind -pm emacs-standard' | grep -vE '^#|: (do-lowercase-version|self-insert)$' | sort > emacs-standardINPUTRC=~/dev/null bash -c 'bind -pm vi-insert' | grep -vE '^#|: (do-lowercase-version|self-insert)$' | sort > vi-insertGet only the additions from emacs-standard:comm -23  emacs-standard vi-insert > vi-insert-emacs-additionsThen, in your ~/.inputrc, add the content of vi-insert-emacs-additions under the lines:(echo set editing-mode vi && echo set keymap vi-insert && cat vi-insert-emacs-additions) >> ~/.inputrcFor your convenience, on bash 4.3.11(1)-release, vi-insert-emacs-additions contents are:\C-a: beginning-of-line\C-b: backward-char\C-]: character-search\C-d: delete-char\C-e: end-of-line\C-f: forward-char\C-g: abort\C-k: kill-line\C-l: clear-screen\C-n: next-history\C-o: operate-and-get-next\C-p: previous-history\C-q: quoted-insert\C-@: set-mark\C-_: undo\C-x\C-?: backward-kill-line\C-x\C-e: edit-and-execute-command\C-x\C-g: abort\C-x\C-r: re-read-init-file\C-x\C-u: undo\C-x\C-v: display-shell-version\C-x\C-x: exchange-point-and-mark\C-xe: call-last-kbd-macro\C-x): end-kbd-macro\C-xg: glob-list-expansions\C-x*: glob-expand-word\C-x!: possible-command-completions\C-x/: possible-filename-completions\C-x@: possible-hostname-completions\C-x~: possible-username-completions\C-x$: possible-variable-completions\C-x(: start-kbd-macro\e0: digit-argument\e1: digit-argument\e2: digit-argument\e3: digit-argument\e4: digit-argument\e5: digit-argument\e6: digit-argument\e7: digit-argument\e8: digit-argument\e9: digit-argument\eb: backward-word\e<: beginning-of-history\e\C-?: backward-kill-word\ec: capitalize-word\e\C-]: character-search-backward\e\C-e: shell-expand-line\e\C-g: abort\e\C-h: backward-kill-word\e\C-i: dynamic-complete-history\e!: complete-command\e/: complete-filename\e@: complete-hostname\e{: complete-into-braces\e~: complete-username\e$: complete-variable\e\C-r: revert-line\e\C-y: yank-nth-arg\e\\: delete-horizontal-space\e-: digit-argument\ed: kill-word\e\e: complete\e>: end-of-history\ef: forward-word\eg: glob-complete-word\e^: history-expand-line\e#: insert-comment\e*: insert-completions\e_: insert-last-argument\e.: insert-last-argument\el: downcase-word\en: non-incremental-forward-search-history\ep: non-incremental-reverse-search-history\e=: possible-completions\e?: possible-completions\er: revert-line\e : set-mark\e&: tilde-expand\et: transpose-words\eu: upcase-word\e_: yank-last-arg\e.: yank-last-arg\ey: yank-popNote: If you add a binding under keymap emacs to vi-movement-mode to try to switch straight to vi-command mode, the prompt doesn't update if you have show-mode-in-prompt on. This is why the above solution adds emacs bindings to vi-insert. This makes for a longer .inputrc, but is required for a complete solution.