I’m having a problem with my terminal for a while now. It seems the combination of bash (or rather readline) and Terminal.app gets confused somehow when I hit the cursor-right key to exit “reverse-i-search” (Control-R) mode. Afterwards, characters to the right of the cursor get duplicated. Vim, being a more complex application, reacts by duplicating the characters in the wrong order.
I’ll show you some screenshots to illustrate the problem.
First of all, this is a new terminal window running “GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0)” (OSX 10.6.4). The prompt is a rather complex one, you can find the code at GitHub. I have no idea whether my prompt is causing the problems, but in Linux it doesn’t. For completeness, I’ll explain it to some degree: The cyan part is showing the Git status for the current directory and generated by
PROMPT_COMMAND. An example
$PS1 looks like this:
\[\e]0;\u@\h:\w\a\]\[\e[1;32m\]\u\[\e[0;32m\]@\[\e[1;30m\]\h\[\e[1;34m\] \w \[\e[0;36m\]di ~? \[\e[1;30m\]\[\e[0;37m\]\A \[\e[0;33m\]\[\e[1;31m\]1\$\[\e[0m\]
For reference, this is the output of
speed 9600 baud; 50 rows; 80 columns; lflags: icanon isig iexten echo echoe -echok echoke -echonl echoctl -echoprt -altwerase -noflsh -tostop -flusho pendin -nokerninfo -extproc iflags: -istrip icrnl -inlcr -igncr ixon -ixoff ixany imaxbel iutf8 -ignbrk brkint -inpck -ignpar -parmrk oflags: opost onlcr -oxtabs -onocr -onlret cflags: cread cs8 -parenb -parodd hupcl -clocal -cstopb -crtscts -dsrflow -dtrflow -mdmbuf cchars: discard = ^O; dsusp = ^Y; eof = ^D; eol = <undef>; eol2 = <undef>; erase = ^?; intr = ^C; kill = ^U; lnext = ^V; min = 1; quit = ^\; reprint = ^R; start = ^Q; status = ^T; stop = ^S; susp = ^Z; time = 0; werase = ^W;
There shouldn’t be any non-default settings here. On to the test case:
echo 126, then hit “cursor left” once, then enter 345, then hit return. Then, I hit Control-R and enter “p”. That’s when I took this first screenshot:
Now, after pressing “cursor right” to exit reverse-i-search mode, the terminal beeps and starts being messed up:
To demonstrate the problem, I do exactly the same
echo as before: I type
echo 126, move one character to the left and type
345, followed by return.
As you can see, for each character I type, another “6” is displayed to the right of the cursor. Things get even worse when I enter Vim. This is my freshly started Vim after entering insert mode and typing a space character:
(The space being shown as underscore is normal, this is the
'list' option in action.)
See how the greeting message moves to the right in a strange way? Another example is this: A fresh Vim after entering
Now, any idea what’s going on here? It’s pretty obvious that working that way is near to impossible. Using
reset works, but doing this everytime isn’t the most convenient thing to do.
If you need any additional information, I’ll be happy to provide it. Also, I’m a pretty experienced CLI user, so you don’t have to explain everything fool-proof.