Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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

Many times when I enter a long command in bash or zsh (these are the only two shells I am positive I have seen this in) the cursor warps to somewhere in the middle of the string I am entering, can anyone explain why this is, and if something can be done about this?

I have noticed that this often happens when I browse the history of my shell (using arrow keys), when I encounter a long entry, the long, new entry will mix up with the previous entry, rendering the text garbled.

I have an example with short strings, which I just noticed:

History contains:

mkdir sune1
mkdir sune2

If I navigate to mkdir sune1, and then to mkdir sune2, I would expect my command line to be mkdir sune2 (since this is what I have now navigated to) - but instead I get mkdir1sune2.

I have noticed this frequently for years, but never let it bother me too much, but I figure it is time for a change! So, any ideas?

share|improve this question
up vote 6 down vote accepted

Your prompt string probably has incorrectly escaped nonprinting characters. If you have anything like color changes in your prompt, you need to put \[ and \] around the terminal escape sequences so bash can tell that they don't take up space on screen — otherwise it miscalculates where the actual command is on screen, and updates it in the wrong place. See this section from TLDP. In zsh, put %{ and %} around escape sequences.

share|improve this answer
    
I do indeed have colors in my prompt, I will try escaping them, or removing them & see if that helps. Thanks! – Jonatan Dec 31 '12 at 20:32
    
Consider using zsh's color module. It should avoid the errors stackoverflow.com/questions/6159856/… – Francisco Jan 9 '13 at 15:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .