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.

iTerm > Manage Profiles

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.

iTerm > Modify global keyboard profile

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 (\eb, word-left) and ESC-f (\ef, word-right), respectively, will do the trick. You can find their explanation among others in the man page of lesskey(1).

iTerm > Shortcut for word movement to the left

iTerm > Shortcut for word movement to the right

That’s it. Now you can use Option← and Option→ for word movement in iTerm!

4. Addendum

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!

Interested in more? You can subscribe to this blog and follow me on Twitter.