I am very used to using alt-left to go to the word before (if you use vim, that's 'b') and alt-right to go to the beginning of the next word.

On Mac terminal however (iterm and iterm2), I am getting ;9D and ;9C respectively. I can use fn+left to go the beginning of the line but I still find that really inconvenient.

Any ideas how to fix this?