The way to distinguish command-mode and insert-mode in Bash's Vi command line editing

后端 未结 3 1481
借酒劲吻你
借酒劲吻你 2020-12-07 16:32

I\'m always little bit confused when bash in vi-mode is switched to insert-mode, because it doesn\'t give any tip about used mode (command or edit). Is there any way to dist

3条回答
  •  离开以前
    2020-12-07 17:16

    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"
    

提交回复
热议问题