I have bash set up with Vi keybindings, however when a command finishes running it returns to insert mode rather than movement mode. I can use bind '"\C-M":vi-movement-mode' in my .bashrc to map the enter key to movement mode, but this does not allow the typed command to be run.
I can use

bind '"jj":vi-movement-mode'
bind '"\C-M":"jj\n"'

to exit out of movement mode when the enter key is pressed, but this returns to insert mode when the command is finished.

This is useful because it means I can enter a command, then use 'k' to scroll back through the command history, or use 'p' to paste another command, without having to exit insert mode every time.

How can I set up a single keybinding to run a command and exit out of insert mode?

Likely unnecessary info but I'm running on cygwin with windows terminal (painful but necessary).


1 Answer 1


Update: As is usual with tech problems, I found the answer 20 mins after posting a question (and a long time searching for a solution). I found using \njj instead of jj\n did the trick. Not particularly nice but it seems to work.

Updated commands for anyone else with the same issue (put in .bashrc)

bind '"jj":vi-movement-mode'
bind '"\C-M":"\njj"'

You must log in to answer this question.

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