I use vi-mode in bash and I have the following in by .inputrc to make the
cursor be block in normal mode and I-beam in insert mode:
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"

When I paste text (that has one or more empty lines at its end) in insert
mode then press esc to switch to normal mode while the cursor is present at
one of these empty lines, a couple of the first characters of the pasted
text get replaced with the character '2' (and the prompt text itslef too
parts of it disappear) and cursor shape remains I-beam (although it should
be block in normal mode)
Same idea when I paste text (that has one or more empty lines at its end)
in normal mode then enter insert mode using i/a/I/A/... while the cursor is
present at one of these empty lines, a couple of the first characters of
the pasted text get replaced with the character '6' (and the prompt text
itself too parts of it disappear) and cursor shape remains block (although
it should be I-beam in insert mode)

Now when I remove the line mentioned above from my .inputrc, no prompt
corruption happens at all and everything works well.

I paste text using xclip via the following functions present in .bashrc
    paste_from_clipboard_normal () {
      local shift=$1
      local head=${READLINE_LINE:0:READLINE_POINT+shift}
      local tail=${READLINE_LINE:READLINE_POINT+shift}
      local paste
      paste=$(xclip -out -selection clipboard; printf x)
      paste=${paste%x}
      local paste_len=${#paste}
      READLINE_LINE=${head}${paste}${tail}
      let READLINE_POINT+=$paste_len+$shift-1
    }
    paste_from_clipboard_insert () {
      local shift=$1
      local head=${READLINE_LINE:0:READLINE_POINT+shift}
      local tail=${READLINE_LINE:READLINE_POINT+shift}
      local paste
      paste=$(xclip -out -selection clipboard; printf x)
      paste=${paste%x}
      local paste_len=${#paste}
      READLINE_LINE=${head}${paste}${tail}
      let READLINE_POINT+=$paste_len+$shift
    }
    bind -m vi-command -x '"P": paste_from_clipboard_normal 1'
    bind -m vi-command -x '"p": paste_from_clipboard_normal 0'
    bind -m vi-command -x '"\ep": paste_from_clipboard_normal 0'
    bind -m vi-command -x '"ð": paste_from_clipboard_normal 0'
    bind -m vi-insert -x '"\ep": paste_from_clipboard_insert 0'
    bind -m vi-insert -x '"ð": paste_from_clipboard_insert 0'

Expected behaviour: should be able to switch modes (where each mode has its
own cursor shape) without the prompt or the text being corrupted.

Reply via email to