Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I’m having a problem with my terminal for a while now. It seems the combination of bash (or rather readline) and 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 stty:

speed 9600 baud; 50 rows; 80 columns;
lflags: icanon isig iexten echo echoe -echok echoke -echonl echoctl
 -echoprt -altwerase -noflsh -tostop -flusho pendin -nokerninfo
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:

I enter 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:

while in ^R mode

Now, after pressing “cursor right” to exit reverse-i-search mode, the terminal beeps and starts being messed up:

after pressing cursor right

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.

messed up command line

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:

messed up Vim

(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 i126<Left>345<Esc>:

Vim after i126<Left>345<Esc>

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.

share|improve this question
have you tried another keyboard? Maybe its broken and sends strange commands..just an idea ;) – user55138 Nov 10 '10 at 11:50
A suggestion for the future: Please make your terminal window smaller before you do a screen capture or crop the images so there's not so much empty space to scroll past when reading your question. – Dennis Williamson Nov 11 '10 at 3:25
Yes, this bugs me as well. However, since it already took me about an hour to post this question (during work time) I was afraid of having to do the screenshots again just because things would scroll and the misbehavior would be worse (or not occur at all). Sorry for spamming your screens. – scy Nov 11 '10 at 12:18
I cannot reproduce the problem with Terminal on Mac OS X Lion 10.7.1, so whatever the source of the problem it may have been fixed at some point. – Chris Page Aug 29 '11 at 11:44
I am able to reproduce the problem with both Terminal and Xterm on Mac OS X Lion 10.7.1 if I set TERM=xterm-color, with your PS1 value and with one of my own. The problem does not occur with TERM=xterm or TERM=xterm-256color. On Lion, the default value is now xterm-256color. xterm-color represents an older branch of Xterm and is not recommended. The TERM value should not affect how codes in PS1 are interpreted, but it could be that bash is sending some control codes from the selected terminfo file and xterm-color specifies something that's incompatible with your prompt's codes. – Chris Page Sep 19 '11 at 11:28
up vote 1 down vote accepted

I wasn't able to reproduce this. I'm using the Pro-profile in and I set 'Declare terminal as' to rxvt. Maybe this helps.

share|improve this answer
Setting the terminal to rxvt solved the problem. (Before, it was xterm-color.) Hope this doesn’t introduce any new problems. Thanks! – scy Nov 10 '10 at 11:54

I cannot say what at this point in time but there is something definitely not right in the PS1 prompt string that you are using that is causing the Terminal to act up when it is using the "xterm-color" emulation. I have the same version of BASH and MacOS as you do over here, and I run my Terminal under xterm-color emulation. The moment I exported the PS1 variable with the value you have provided in the question and did the trick you mention inside the reverse search mode, I could see the exact same behaviour on my Terminal as you do on yours.

share|improve this answer
Thanks, I’ll have a look at it. – scy Nov 10 '10 at 19:57
@Scytale - It's the colours. I've got the same problem, but if I remove all escape sequences (like \e[0;36m) from my PS1 then ctrl+r works as expected. – Nicholas White Mar 16 '13 at 1:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.