When I ssh into a Linux server from bash Terminal, I can use CTRL+A to return to the start of line properly, and CTRL+E to go to end of line and everything works fine.

When I use bash locally on my Mac, when I use CTRL+A it logically goes back to the start of the line, but doesn't display the cursor in the correct place. It displays the cursor 7 or so characters off and doesn't update the line text correct.


find . -name "hello.cpp"


find . -name "hello.cpp"
       ^~~ cursor shows here ????

Insert "this is a test" (just to show)


find . this is a test -name "hello.cpp"
                      ^~~ cursor is still here ???
       ^~~~~~~~~~~~~^ text inserted here ???
^~~~~~^ unchanged for some reason

Command executed

this is a test find . -name "hello.cpp"

I use the same

PS1=\n \e[1;95m \u@\h \e[0;32m\w \e[1;30m $(__git_ps1 " (%s)" ) \n \e[1;95m \@ \n $ \e[0;30m

as I do on Linux.

Version Info

  • bash version: 3.2.57(1)
  • terminal version: 2.6.1 (361.1)
  • OS X El Capitan, 10.11.5
  • 3
    Actually the reason seems to be the opposite you need [ ] to enclose the colour shift codes as per the article quoted there ibm.com/developerworks/linux/library/l-tip-prompt
    – mmmmmm
    Commented Jun 5, 2016 at 19:21
  • Adding \[ and \] around the colors solved the problem. It's actually the inverse of the other problem, which I'd recommend changing the subject line for as this is a more general issue than just for "emacs style". Do you want me to mark as duplicate even though they're inversed? I think this subject would make it easier to find.
    – pyj
    Commented Jun 5, 2016 at 20:43
  • Currently it is not a duplicate but I suspect a question could be written using the other answer to produce a common question
    – mmmmmm
    Commented Jun 6, 2016 at 10:08
  • @Mark I converted your comment to an answer. Questions should have answers. If you create your own answer (you can copy the one I added if you want) then I will delete mine. Commented Oct 27, 2016 at 21:58

1 Answer 1


Add \[ and \] around the colour codes to enable bash to calculate the line length correctly. Something like this:

PS1=\n \[\e[1;95m\] \u@\h \[\e[0;32m\]\w \[\e[1;30m\] $(__git_ps1 " (%s)" ) \n \[\e[1;95m\] \@ \n $ \[\e[0;30m\]

(This answer is taken from @Mark's comment on the question.)

This fix works for other commands like Ctrl-W

You must log in to answer this question.

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