10

Having done a little research on this, I know that option+left arrow and option+right arrow do not by default move by word in the OS X Terminal application. But mine did, until about a week ago.

The only thing that's changed is oh-my-zsh updated. I see that it has

bindkey "^[[1;5C" forward-word  
bindkey "^[[1;5D" backward-word

defined but I don't know what those keys are. GitHub's last recorded change to the file was 24 days go and not related to those keys, so this must predate the latest update.

I have also tried the "Use option as meta key" option under Preferences > Settings > Keyboard. That only results in printing [D and [C when I hit option+left arrow and option+right arrow.

ele
  • 6,021
  • 5
  • 25
  • 35
  • Can't replicate. It works as expected for my. Running Mountain Lion (1.8.5). – rdodev Dec 27 '13 at 15:57
  • In my Terminal.app > Preferences > Keyboard shows `option cursor right` and `left` do those show for you and what values do they have? – rdodev Dec 27 '13 at 16:00
  • You mean in the Key:Action list? No, I don't have them. – ele Dec 27 '13 at 16:07
  • I do have a Control Cursor Right bound to `\033[5C` and a Control Cursor Left bound to `\033[5D`. See [here](https://www.dropbox.com/s/v2h85ju3d2jx5l8/Screenshot%202013-12-27%2010.11.14.png). – ele Dec 27 '13 at 16:11
  • In that list find or add `option cursor right` value `\033f` and `option cursor left` value `\033b`. Quit and restart Terminal.app. – rdodev Dec 27 '13 at 16:22
  • 1
    Yes, after some fiddling I was able to add that myself, using [this answer](http://stackoverflow.com/a/81307/1457116) supplemented by [Allan Odegaard's old blog post](http://blog.macromates.com/2006/word-movement-in-terminal/). I didn't need to select "Use option as meta key," nor did I need to restart Terminal. The keystrokes even apply to other Terminal profiles (Basic, Pro, etc). – ele Dec 27 '13 at 16:29

1 Answers1

16

One way to fix your issue is to:

  • In Terminal.app > preferences > Settings > Keyboard there's a Key -> Action list.
  • In that list find or add option cursor left and option cursor right and set their values to \033b and \033f respectively.
  • Quit and restart Terminal.app
Mladen Janjetovic
  • 13,844
  • 8
  • 72
  • 82
rdodev
  • 3,164
  • 3
  • 26
  • 34
  • 13
    In iTerm2 this also works, but you select `Send Escape Sequence` and `f` and `b` respectively for your current profile (Preferences > Profiles > *Default > Keys > Key Mappings for Ctrl Left/Right arrow) – Yzmir Ramirez Jan 06 '18 at 21:31
  • Adding a blog link for this setup on iterm2 having explaination https://coderwall.com/p/h6yfda/use-and-to-jump-forwards-backwards-words-in-iterm-2-on-os-x – M. Habib May 11 '23 at 15:18