Last Updated: November 29, 2022
·
333.1K
· e-dard

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.

Picture

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

Picture

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.

46 Responses
Add your response

thx for the trick :)

over 1 year ago ·

Very useful, thanks...

over 1 year ago ·

Thank you, very useful!

over 1 year ago ·

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

over 1 year ago ·

Thank you. This worked well with my OSX 10.9 mac.

1 Feb 2014

over 1 year ago ·

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

over 1 year ago ·

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?

over 1 year ago ·

Why did I allow myself to continue living without this for so long?

over 1 year ago ·

Thanks. Succint and clear.

over 1 year ago ·

I would only add
alt + backspace : Send HEX "0x17"

https://code.google.com/p/iterm2/issues/detail?id=1052

over 1 year ago ·

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

over 1 year ago ·

Thanks, just what I was looking for! :)

over 1 year ago ·

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

over 1 year ago ·

Thank you very much!

over 1 year ago ·

Awesome

over 1 year ago ·

Thanks, that saved lots of time!! :D

over 1 year ago ·

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

over 1 year ago ·

This is great!

over 1 year ago ·

Thanks really helpful

over 1 year ago ·

Thank you, saved lots of time :)

over 1 year ago ·

fantastic! woot!

over 1 year ago ·

love it

over 1 year ago ·

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

over 1 year ago ·

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

over 1 year ago ·

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
over 1 year ago ·

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

over 1 year ago ·

Thank you! =)

over 1 year ago ·

Neat, now I finally can convert to Iterm 2!

over 1 year ago ·

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

over 1 year ago ·

Nice ..
Thanks for this trick !!

over 1 year ago ·

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

over 1 year ago ·

Thank you so much!

over 1 year ago ·

Beautiful and needed. thank you

over 1 year ago ·

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

K

over 1 year ago ·

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.

over 1 year ago ·

alternative option + f or option + b

over 1 year ago ·

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?

over 1 year ago ·

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?

over 1 year ago ·

nice!

over 1 year ago ·

Quick and easy. Thanks!

over 1 year ago ·

This is such an amazingly useful trick, it really ought to be a default settings. Thanks a lot!

over 1 year ago ·

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

over 1 year ago ·

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.

over 1 year ago ·

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.

over 1 year ago ·

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.

over 1 year ago ·

Thanks a million for this, very useful in iTerm when you need to alter single words in commands

over 1 year ago ·