Backwards-word, forwards-word, and kill-word in iTerm 2

I recently switched to iTerm 2, and my biggest pain point was getting back the proper behavior of Option-Left, Option-Right, and Option-Delete: move back a word, move forward a word, and delete a word. These three are standard shortcuts in every Mac app, and not having it in iTerm 2 is painful.

So, a quick description. Option-Left and Option-Right are easy -- the most common way to achieve these is by sending the control sequence <Esc>-b and <Esc>-f, or \[b and \[f. In iTerm 2, you can do that by just pulling up the session configuration (in the preferences or via Cmd-I, going to the Keyboard tab, hitting the + sign at the bottom (of the right pane), and hitting Option-Right in the keyboard shortcut box. Then select `Send escape sequence' from the action box and type f in the box below it:

You can then do the same for Option-Left and b.

Option-Del is slightly more complicated. Deleting a word is done by sending \[^h, which is the equivalent of <Esc>-<Ctrl+H>. However, you can't insert Ctrl-H directly in the dialog above. Thanks to this fine blog post on word shortcuts in iTerm, we find out that Ctrl-H is the equivalent of the character code 0x7f, which we can insert in a few ways. I'll describe the easiest for me, the other two are in the linked blog post.

First, show the character viewer from the input method menu:

Then, select the code tables entry from the `view' box:

Finally, scroll the bottom pane down to the 0070 row  and select the very last column, under F:

Then make sure the box for the character where you put the f and the b for Option-Left and -Right is selected, and click the insert button in the bottom right of the character viewer. Nothing will appear to show up in the text box, but it is there! HIt OK, and you're done!
14 responses
Thanks! The screenshots were perfect -- for some reason I wasn't getting my option-left/option-right to work!
Awesome! Glad it was helpful! :)
Amazing, very helpful. I love iTerm2 and option delete was the only stupid thing not working.
I love its transparency.
For the Option-Delete deal, I just figured out that you can do it by using "Send Hex Code" instead of "Send Escape Sequence" and use the value "0x1b 0x7f" which is <esc>+<ctrl-h>
Oh, badass! Much easier, thanks for mentioning that!
The problem with this method is you can no longer (to my knowledge) type a hash character with alt+3 which is essential for python comments.

Are you aware of a work around, or do I need to completely reassign all my shortcut keys?


Scratch that. It works fine.
For the extra Option-Delete tip Sam mentioned, you need to manually type the string (without quotes), rather than paste it in for some reason.
5 visitors upvoted this post.