When using vi mode (set -o vi) with Bash, it would be nice to have a prompt that depends on the mode you are currently in (insert or command). How does one find out this edi
.inputrcFirst you should make sure that you're running a bash version higher than 4.3:
$ bash --version
GNU bash, version 4.4
Then put the following lines in your ~/.inputrc:
#################### VIM ####################
# FOR MORE INFORMATION CHECK:
# https://wiki.archlinux.org/index.php/Readline
# TURN ON VIM (E.G. FOR READLINE)
set editing-mode vi
# SHOW THE VIM MODE IN THE PROMPT (COMMAND OR INSERT)
set show-mode-in-prompt on
# SET THE MODE STRING AND CURSOR TO INDICATE THE VIM MODE
# FOR THE NUMBER AFTER `\e[`:
# 0: blinking block
# 1: blinking block (default)
# 2: steady block
# 3: blinking underline
# 4: steady underline
# 5: blinking bar (xterm)
# 6: steady bar (xterm)
set vi-ins-mode-string (ins)\1\e[5 q\2
set vi-cmd-mode-string (cmd)\1\e[1 q\2
In command mode, the cursor is displayed as block.
In insert mode, the cursor is displayed as vertical bar.
The prompt itself will then look like this depending on the mode:
(cmd)$ ...
(ins)$ ...