One of the things that has always bothered me about iTerm on Mac OS X is the lack of default keyboard shortcuts for moving from word to word like Ctrl← (cursor-left) and Ctrl→ (cursor-right) on standard Linux terminals. I’m not that familiar with shell escape sequences, so I was quite happy when I found out how to use them for adding word movement support to iTerm.
It’s quite easy actually and involves just a few steps. Add the end, you can use Option← and Option→ for word movement to the left and right, respectively (if you prefer the Linux setup, you just use the Ctrl modifier instead of Option in the following steps).
1. Manage Profiles
First, open the Manage Profiles menu in iTerm.
2. Modify the global keyboard profile
Now, we will add two new shortcuts to the global keyboard file. Click the
+ button as shown in the screenshot below to add a new shortcut.
Ok ok; admittedly, you can already see in this screenshot that the shortcuts we are about to add do already exist – I was just too lazy to remove them before taking the picture.
3. Configure the word movement shortcuts
We need two shortcuts in total, one for word movement to the left with Option← and one for word movement to the right with Option→. The shell escape sequences ESC-b (
word-left) and ESC-f (
word-right), respectively, will do the trick. You can find their explanation among others in the man page of lesskey(1).
That’s it. Now you can use Option← and Option→ for word movement in iTerm!
If you want to enable “backward-kill-word”, add another shortcut with the following configuration.
Go to Bookmarks > Manage Profiles… and open Keyboard Profiles > Global (just like in the previous sections). Add a new mapping (“+” sign) and configure its parameters:
- Key: delete
- Modifier: Option
- Action: “send hex code”, and enter “17” (without the quotes)
Now you can kill word-by-word (from right to left aka backwards) by hitting Option-Backspace. Thanks to reader Lasantha Kularatne for the tip!