I can't speak for iTerm but these are the keybindings I used to solve this problem under GNOME Terminal, on Fedora 19, running ZSH 5.0.7 with Oh-my-zsh:
bindkey "\e[1;3C" forward-word
bindkey "\e[1;3D" backward-word
where \e
== The escape-key-sequence(as documented under section 4.1.1)
and [
== O
(uppercase O; as documented under section 4.2.1), in some cases. For e.g. under tmux
this substitution is necessary for me, however without tmux
it is required that no substitution be made and [
== [
The key codes for a sequence can be obtained using cat
and pressing the desired sequence. For example the results of pressing <Alt+Right>
should be interpreted like so:
$ cat
^[[1;3C
^[
== \e
== The escape-key-sequence
[
== [
without tmux
OR
[
== O
(uppercase o) with tmux
1;3
== I'm not sure about this one, but it should logically mean <Alt>
C
== The right arrow key
Then this sequence is given to bindkey
in the ~/.zshrc
file for persistance, as the first argument, and is bound, meaning that the keystroke in argument one will execute a particular editor command (or widget in zsh terms), to the widget, which in the first line of the above example is forward-word
.
The ~/.zshrc
should be re-sourced after these two commands are appended to it with:
$ source ~/.zshrc
Now one annoyance on my system is that this particular combination caused the terminal emulator to issue a beep each time the command was issued, this I remedied by disabling the
'Edit'->'Profile Preferences'->'Terminal Bell'
checkbox.
People interested in this question may also be interested to know that zsh words are not bash words.
FOO=BAR
is one word to zsh and 2 words to bash. Similarly, if you set your cursor to the end offoo --bar
and do alt+backspace, in bash you will havefoo --
and in zsh you will havefoo
. Zsh adds a lot of features to bash, but it also has lots of insane defaults to override. – weberc2 – 2017-11-06T20:08:11.143