I'm trying to get Bash to mimic the behaviour of KornShell93 (ksh) when the shells are in Vi command line editing mode.

KornShell defaults to "Vi normal mode" (a.k.a. "command" mode) and it also places the cursor at the very start of the command line when stepping backwards through the command line history. This is in contrast to Bash, which puts you in "Vi insert mode" and at the end of the command line.

In the answers to "Bash vi mode configuration to default to command mode", it pretty much concluded that there's no way to have Bash default to "Vi normal mode" when Vi command line editing is enabled.

This was more than five years ago now, and I wonder if this has changed since then?

And what about automatically placing the cursor at the start of the command line? Is there some to me unbeknown Readline magic that can help me with this?

I'm using Bash version 4.4.5(1)-release compiled from source (the OpenBSD shells/bash port) on OpenBSD-current (January 2017).

  • 1
    As a data point, Zsh behaves like Bash^H^H^H^HReadline, not like ksh. (Bash's behaviour isn't really Bash's, it's Readline's, which Bash uses.)
    – Celada
    Commented Jan 7, 2017 at 17:47

1 Answer 1


It seems that there is no adequate way to insert an Esc in the command line.

While in vi-insert most alpha/numeric keys are used. Esc is quite far away, and any chord (like Alt-j (which works)) seem more complex than desired. So, there is a way to make two keys convert to a configurable string.

The workaround works by using the idea from This answer

Just add this to .inputrc:

 set editing-mode vi
 set vi-ins-mode-string \1\e[6 q\2
 set vi-cmd-mode-string \1\e[2 q\2

 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

By that, no matter where you start either emacs or vi, pressing both jk will place you in vi-command mode at the start of the line.

Additionally, it allows you to switch to emacs mode with Esc-e.

  • I can't upvote this enough! I got rid of the emacs stuff and I only need the "jk" shortcut, I don't need "kj", so I simply have: set editing-mode vi set vi-ins-mode-string \1\e[6 q\2 set vi-cmd-mode-string \1\e[2 q\2 set keymap vi-insert "jk": vi-movement-mode and now I am happy! Commented May 6, 2020 at 15:06

You must log in to answer this question.

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