Thanks. There was a combination of spaces and tabs so I've changed them all to tabs.
One problem I've noticed is that if I have a multi-line visual selection that I want to wrap (e.g. in an if block), the tab before ${VISUAL} only causes the first line to be indented. I don't think I'm doing anything different from the other languages here. Is there any way to get the whole visual selection indented?