The way to distinguish command-mode and insert-mode in Bash's Vi command line editing
in /etc/inputrc (or ~/.inputrc) add this:
set show-mode-in-prompt on
this will prefix your prompt with + while in insert-mode, and : while in command mode in bash 4.3
EDIT:in the latest version of bash 4.4, you will instead get a prompt prefixed with "(ins)" or "(cmd)" by default. but, you can change that:
set vi-ins-mode-string "+"set vi-cmd-mode-string ":"
also, you can use color codes like '\e[1;31m', but surround them with '\1' and '\2' to keep readline happy:
set vi-cmd-mode-string "\1\e[1;31m\2:\1\e[0m\2"
Building on @Isaac Hanson's answer you can set the cursor style to reflect the mode (just like in VIM) by setting these in your .inputrc
:
set editing-mode viset show-mode-in-prompt onset vi-ins-mode-string \1\e[6 q\2set vi-cmd-mode-string \1\e[2 q\2# optionally:# switch to block cursor before executing a commandset keymap vi-insertRETURN: "\e\n"
This will give you a beam cursor in insert mode or a block cursor for normal mode.
Other options (replace the number after \e[
):
Ps = 0 -> blinking block. Ps = 1 -> blinking block (default). Ps = 2 -> steady block. Ps = 3 -> blinking underline. Ps = 4 -> steady underline. Ps = 5 -> blinking bar (xterm). Ps = 6 -> steady bar (xterm).
Your terminal must support DECSCURSR (like xterm, urxvt, iTerm2). TMUX also supports these (if you set TERM=xterm-256color
outside tmux).
After years of using vi mode in korn shell, I have basically trained myself to just tap ESC
a few times before I type any commands, and ESC
then i
to start typing.
The basic premise being that if you just hit ESC
, you know precisely what mode you are in.