Cursor does not go begining of the line

consolecursorterminal

Hello I am trying to go begining of the line. neither left arrow key or ctrl + a
lets me do it. everytime it keeps couple letters on the right.
however its a visual bug my cursor is actually in the begining

I am not exactly sure why it happens but it happen both on default terminal app and iterm2

enter image description here

enter image description here

P.S : it isnt only happens with this command I just didnt know what else to write to show.

Best Answer

That issue is related to your $PS1, you're probably missing some escape character. This one should work:

PS1="\[\e[1;31m\]\u[\w]$\[\e[0m\] "