Use ⌥ ← and ⌥→ to jump forwards / backwards words in iTerm 2, on OS X
By default in iTerm 2, it's a pain to skip between words.
Here's how you can configure iTerm 2 on OSX to allow you to use ⌥ ← and ⌥→ to do just that.
First you need to set your left ⌥ key to act as an escape character.
Second you need to either locate the current shortcut for ⌥ ← or create a new one, in the Profile Shortcut Keys, with the following settings:
- Keyboard Shortcut: ⌥←
- Action: Send Escape Sequence
- Esc+: b
Third, repeat for the ⌥→ keyboard shortcut with the following settings:
- Keyboard Shortcut: ⌥→
- Action: Send Escape Sequence
- Esc+: f
You're done! Now you can skip entire words on the command line by holding down the left ⌥ key and hitting ← or →
To make this work for the right option key you need to set the key modifier to act as an Escape Sequence, a la the first step.
Written by Edward Robinson
Related protips
46 Responses

thx for the trick :)

Very useful, thanks...

Thank you, very useful!

Awesome! I wonder, this works in vim also (brew vim) but only ALT left, right doesn't work, do you know why? thanks!

Thank you. This worked well with my OSX 10.9 mac.
1 Feb 2014

Thank you. I spent some time looking for a solution and your trick finally fixed my problem.

Interestingly, this doesn't work for me. OPTION+LEFT
still gives [D
, OPTION+RIGHT
still gives [C
. Are there any other possible sources of conflict beyond the general keyboard settings and profile keys?

Why did I allow myself to continue living without this for so long?
Thanks. Succint and clear.
I would only add
alt + backspace : Send HEX "0x17"

Thanks a lot mate! I went through quite a few blogs before this one worked for me!

Thanks, just what I was looking for! :)

Thank you very much; just landed on a mac and it was one of the biggest pain in the neck.
Thank you very much!

Awesome

Thanks, that saved lots of time!! :D

googled "iterm skip words"... first result and does what I need. thank you!

This is great!

Thanks really helpful
Thank you, saved lots of time :)

fantastic! woot!

love it

This has been driving me crazy since I switched to a Mac. Thank you SO MUCH! :)

On Terminal.app: Settings->Keyboard->"Use Option as Meta key".
"Alt-." is my favourite. Repeat the last word of the previous command.

In case anyone is still looking for a solution to this and lands here, you may need to edit your ~/.inputrc as well:
"\e\e[C": forward-word
"\e\e[D": backward-word

Wow! Just installed iTerm2 and can't stop admiring it! It's like the best thing that happened in my programming life since vim!

Thank you! =)

Neat, now I finally can convert to Iterm 2!

Nevermind... was looking at "Keys" and not "Profiles > Keys"

Nice ..
Thanks for this trick !!

This was the one thing that was driving me crazy when switching to iTerm. Thanks for posting!

Thank you so much!

Beautiful and needed. thank you

This made me go back to Terminal (Yosemite). Total waste of time in iTerm2.
Thanks anyways for sharing this!
K

Why wouldn't they have this by default... I just installed iterm2 and use option-left/right all the time and if I hadn't found this page I may have scrapped it.
alternative option + f or option + b
i really do not get, why this isn't preset in iterm. anyway, if you change the alt key behaviour, access to pipe | and others is gone too. so not really a solution afais?
I did this and also edited my inputrc and moving left by one word works just fine but trying to skip right instead prints "ord-right". Any ideas what's going wrong here?
nice!
Quick and easy. Thanks!
This is such an amazingly useful trick, it really ought to be a default settings. Thanks a lot!
Isn't it a default now? I have these sequences already prefilled:
option + left: send hexcode 0x1b 0x1b 0x5b 0x44
option + right: send hexcode 0x1b 0x1b 0x5b 0x43

Thanks so much. This is one of those things that always proves frustrating, just not usually frustrating enough to try and find a fix. Glad I was able to quickly find your solution and alleviate this ongoing frustration.

Thanks for the article. I don't know why iTerm2 doesn't do this by default, I agree. Also, there's Preset in iTerm called "natural text editing" under Preferences:Profiles:Keys that does this now.
If you are still having a problem, it's because the original use wasn't removed yet. You want to find the original ⌥<- and ⌥-> by going to profiles -> Keys -> Key Mappings and scrolling down and deleting these two from the list.
Thanks a million for this, very useful in iTerm when you need to alter single words in commands