Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For some reason I am unable to bind Ctrl-Left Arrow and Ctrl-Right Arrow to move between words in ZSH after installing oh-my-zsh on my MacBook Pro.

In iTerm2 I have my keybindings configured to "Send Escape Sequence" [1;5D and [1;5C, which worked before installing oh-my-zsh.

I also tried uncommenting

bindkey '^[^[[C' emacs-forward-word
bindkey '^[^[[D' emacs-backward-word

in ~/.oh-my-zsh/lib/key-bindings.zsh, also to no avail. In both scenarios, hitting Ctrl-Left/Right just sends "5D" and "5C" to the screen.

TLDR: Has anyone gotten Ctrl-Left and Ctrl-Right to move between words when using oh-my-zsh?

share|improve this question

migrated from Jun 23 '11 at 10:28

This question came from our site for system and network administrators.

Change your bindkey lines to:

bindkey '^[[1;5C' emacs-forward-word
bindkey '^[[1;5D' emacs-backward-word
share|improve this answer

This one worked for me:

bindkey "[C" emacs-forward-word   #control left
bindkey "[D" backward-word        #control right

In fact, I pressed Control+left and Control+right between the "" and that did the magic.

share|improve this answer

Press ^v(Ctrl-v) or cat in the zsh shell, followed by the key-combinations(Ctrl+left) whichever you wanna use, to get the corresponding bindkey value. Use this output in the command. It varies from system to system depending on the terminal driver, etc.

In my case Ctrl-left was ^[O5D. Hence, bindkey '^[O5D' backward-word

If you wanna go one step ahead, provides the idea to generalize zsh key bindings, with the help of the cmd autoload zkbd ; zkbd. Once done, add the following line, source ~/.zkbd/$TERM-${${DISPLAY:t}:-$VENDOR-$OSTYPE} to your .zshrc. From now on, you may write it like [[ -n ${key[Left]} ]] && bindkey "${key[Left]}" backward-char. In this way, you can copy the same .zshrc to different machines too.

Additional info: Peter Stephenson says ...the function keys on your keyboard... It depends a good deal on how your windowing system or terminal driver handles them... Hence it is better to validate all those key binds before running any such script, though it might not vary in most of the cases.

For detailed understanding of key bindings for zsh, check this guide.

If you wanna know how a key pressed is displayed,

share|improve this answer

So you have your terminal emulator sending one CSI sequence (ESC+[+1;5C) for the key, but you've told your shell with the bindkey command to watch the terminal input for a different CSI sequence (ESC+ESC+[+C), and you are wondering why this doesn't work?

It doesn't work for the very obvious reason.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .