URL: <https://savannah.gnu.org/bugs/?68602>
Summary: prompt text corrupts when switching modes in vi-mode
Group: The GNU Bourne-Again SHell
Submitter: tmp0x
Submitted: Fri 07 Aug 2026 12:21:33 AM UTC
Category: None
Severity: 3 - Normal
Priority: 5 - Normal
Item Group: None
Status: None
Privacy: Public
Assigned to: None
Open/Closed: Open
Discussion Lock: Unlocked
_______________________________________________________
Follow-up Comments:
-------------------------------------------------------
Date: Fri 07 Aug 2026 12:21:33 AM UTC By: tmp0x <tmp0x>
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2
uname output: Linux debian 6.1.0-22-amd64 #1 SMP PREEMPT_DYNAMIC Debian
6.1.94-1 (2024-06-21) x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu
Bash Version: 5.3
Patch Level: 0
Release Status: release
Description:
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.
Repeat-By:
In vi-mode, paste multi-line text which has one or more empty lines at its
end, then switch modes (normal & insert) while the cursor is at one of the
empty lines
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?68602>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
signature.asc
Description: PGP signature
