Bash – How to display the current mode of `vi` command-line editing (`set editing-mode vi`) in bash or tmux

bashterminaltmux

I use vi command-line editing (set editing-mode vi in ~/.inputrc) in Bash shells.

However, I find it frustrating, that I cannot see whether vi command-line editing is currently in command or input mode.

Is there someway to display the current mode of vi command-line editing in Bash or tmux?

Best Answer

You can set the cursor style to reflect the mode by setting these in your .inputrc:

set editing-mode vi
set show-mode-in-prompt on
set vi-ins-mode-string \1\e[6 q\2
set vi-cmd-mode-string \1\e[2 q\2

# optionally:
# switch to block cursor before executing a command
set keymap vi-insert
RETURN: "\e\n"

This will give you a beam cursor in insert mode or a block cursor for normal mode.

For more see https://stackoverflow.com/a/42107711/52817

Related Question