Bash Ctrl-A Returns to Start of Line but Doesn't Display Properly 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.

Example

find . -name "hello.cpp"


CTRL+A!

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


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

Displays:

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
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.)