Different bash prompt for different vi editing mode?

后端 未结 9 986
深忆病人
深忆病人 2020-12-22 16:45

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

9条回答
  •  不知归路
    2020-12-22 17:13

    Different Prompt and Cursor Style via .inputrc

    First 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)$ ...
    

提交回复
热议问题