Using Alt/Cmd + Right/Left Arrow in iTerm
- Go to iTerm Preferences → Profiles
- select your profile
- then the
Keys
tab - Click
Load Preset
... - and choose
Natural Text Editing
Go to iTerm Preferences → Profiles, select your profile, then the Keys tab. Find ⌥← and ⌥→ and set them to send escape sequence b
and send escape sequence f
respectively.
If you use ⌘→ and ←⌘ you will need to remap the next and previous tab shortcuts which are set to those as default. Terminal uses ⇧⌘→ and ⇧⌘← for these.
You can do this under Profiles, or just globally under Keys (shown below) if you wish to set it globally. Note that settings in Profiles override global settings in Keys.
If you use bash, you can also add
"\e\e[D": backward-word
"\e\e[C": forward-word
to ~/.inputrc
.
Go to: Preferences > Profiles > Keys
Look for the actions of ⌥← and ⌥→. They would have been mapped to: Send Hex codes
Change them to Send Escape sequence with Esc+B for backward and Esc+F for forward.
For zsh I inserted in ~/.zshrc
bindkey "\e\e[D" backward-word
bindkey "\e\e[C" forward-word
for bash I inserted in ~/.inputrc
"\e\e[D": backward-word
"\e\e[C": forward-word