Jumping to the start and end of the line
In case you didn't know, you can jump to the start or end of the line using Ctrl-a or Ctrl-e when you're in the command line.
Map Ctrl-a to Cmd ←
It's actually pretty simple. Go to the preferences (Cmd + ,) and then to Keys.
Then simply add another key. Refer to the screenshot for more information.
Map Ctrl-e to Cmd →
Similar to mapping Ctrl-a, add a new key combination.
Adding Escape Sequences
Another cool thing is to jump forwards and backwards by word. You can
do this in vanilla command line by typing ESC followed by f
or b
.
Map ESC-b to Option ←
Similar to the mappings above, just add a key mapping, but this time add an escape sequence instead of just "Send text" (as shown in the screenshot).
For the forward key, just do the opposite.
Caveats
The default iTerm2 profile has a default mapping for Option + Left and Right arrows. I chose to simply delete these mappings.