Problem with Ctrl-Left/Right bindings in oh-my-zsh
Change your bindkey lines to:
bindkey '^[[1;5C' emacs-forward-word
bindkey '^[[1;5D' emacs-backward-word
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, https://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, https://unix.stackexchange.com/questions/116629/how-do-keyboard-input-and-text-output-work/116630#116630