I believe $fg[color] contains something like \e[32m ? If so, it should be enclosed in %{…%} to indicate that this sequence has no width. But it is much better if you forget about all this and use %F{color} for the foreground, %K{color} for the background and %f / %k to cancel them instead of $reset_color . You have to do
setopt promptsubst setopt promptpercent
for this to work (you probably already have this).
This space is the width of the colors, and they cause the cursor to go wrong. The problem here is that the zsh cant query terminal with the question "Hey, did I get some text, what is its width?" instead, you need to calculate the width yourself.
source share