Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 serverfault.com 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, http://stackoverflow.com/a/8645267/2538943 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. http://zsh.sourceforge.net/Guide/zshguide04.html.

If you wanna know how a key pressed is displayed, http://unix.stackexchange.com/questions/116629/how-do-keyboard-input-and-text-output-work/116630#116630

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.