I have a problem with command editing in bash. If all of the following are true...

  1. My (single-line) prompt is particularly long.
  2. The terminal window is relatively narrow.
  3. I pressed Ctrl+C to exit the previous process, so that ^C is displayed at the left of the line.
  4. The command I'm editing wraps to the next line.

...then the editing is messed up. I end up replacing characters offset by 2 positions from the ones I thought I was editing.

Similar things happen if, at step 4, I type in a command that spans multiple lines (rather than pressing Up). I can backspace onto the previous line, and then delete two characters of my prompt.

Basically this:

(Some output)
^Cuser@host:~/path/to/somewhere $ some long command
that wraps

Is broken by the ^C that appears at the start of the line.

I've tried some other commands (e.g. sleep 30), and the ^C appears on a line by itself, and the prompt appears on the next line. This only seems to happen with node.js: node some_command_that_wraps.js.

In case it's important, I have a brightly-coloured, git-integrated PROMPT_COMMAND. You can find it on github, in case I've done something stupid in that.


My PS1 is (for example) set to (I've wrapped it slightly):

\[\e[0;97m\]{\[\e[0;94m\]master\[\e[0;92m\]\[\e[0;91m\] ~1\[\e[0;97m\]}

...which displays (with more colour):

roger@roger-p5q:~/Source/rlipscombe/bash_profile [master ~1] $ 

As far as I can tell, the escape characters are correctly non-countable (using \[ .. \]).

How do I either:

  • Get bash to detect the ^C and move to the next line?, or
  • Not mess up the command editing?
  • Can you provide your bash version and the output of stty -a?
    – phemmer
    Oct 13, 2013 at 14:05

1 Answer 1


If you just want a solution so you can carry on working; under these circumstances I simply hit enter once or twice and end up with a clean prompt.

If some previous output has contributed to the mess with 'wierd' characters, I might also issue the reset command.

If you're really curious and need to figure out the root cause, I'm afraid I've never figured out these particular intricacies of readline ...

You must log in to answer this question.

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