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

后端 未结 3 1501
借酒劲吻你
借酒劲吻你 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:21

    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 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.

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

提交回复
热议问题