Copied from How to get Cmd-left/right working with iTerm2 and Vim (without requiring .vimrc changes)?
To jump between words and start/end of lines in iTerm2 pick one of the two solutions below.
1. Simple solution (recommended)
- Open Preferences
- Click “Profile” tab
- Select a profile in the list on the left (eg “Default”) and click “Keys” tab
- Click the “Presets” dropdown and select “Natural Text Editing”
2. Mapping keys manually (Advanced)
If you don’t want to use the “Natural Text Editing” preset mentioned above, you can map the keys you need manually:
- Open Preferences
- Click “Keys” tab
- Click the
[+]
icon
You can now add the following keyboard shortcuts:
Move cursor one word left
- Keyboard shortcut: ⌥ + ←
- Action: Send Hex Code
- Code:
0x1b 0x62
Move cursor one word right
- Keyboard Combination: ⌥ + →
- Action: Send Hex Code
- Code:
0x1b 0x66
Move cursor to beginning of line
- Keyboard Combination: ⌘ + ←
- Action: Send Hex Code
- Code:
0x01
Move cursor to end of line
- Keyboard Combination: ⌘ + →
- Action: Send Hex Code
- Code:
0x05
Delete word
- Keyboard Combination: ⌥ + ←Delete
- Action: Send Hex Code
- Code:
0x1b 0x08
Delete line
- Keyboard Combination: ⌘ + ←Delete
- Action: Send Hex Code
- Code:
0x15
Undo
- Keyboard Combination: ⌘ + z
- Action: Send Hex Code
- Code:
0x1f
Don’t forget to remove the previous bindings:
- Open the “Profiles” tab
- Click the sub-tab ”Keys”
- Remove the mappings for key combinations ⌥ + ← and ⌥ + →