If you’re a Macintosh user, it is probably second nature to use ⌥← to go back one word and ⌥→ to forward a word. Similarly, ⌘← will bring you to the beginning of a line while ⌘→ will jump you to the end. However, by default, iTerm 2, a great replacement for macOS’s included Terminal application, is not set up to work this way. Fortunately, it is possible to map your keys in a way to get this functionality.
In iTerm, go to your Preferences and then the Profiles tab. Click on the Profile you are using and choose the “Keys” tab.
From there, you can click on the + button below the existing Key Mappings and use the following settings to emulate the default Macintosh behavior.
Back One Word
Forward One Word
Go to Beginning of Line
Go to End of Line