I just recently switched from bash to zsh, however I miss my Alt+LeftArrowKey and Alt+RightArrowKey to go back and forth a word at a
Run cat
then press keys to see the codes your shortcut send.
(Press Ctrl+C to kill the cat
when you're done.)
For me, (ubuntu, konsole, xterm) pressing Alt+← sends ^[[1;3D
, so i would put in my .zshrc
bindkey "^[[1;3C" forward-word
bindkey "^[[1;3D" backward-word
(Actually I prefer to use Ctrl + arrow to move word by word, like in a normal textbox under windows or linux gui.)
Related question: Fix key settings (Home/End/Insert/Delete) in .zshrc when running Zsh in Terminator Terminal Emulator
To make it work for me I used this answer, however I had to swap the codes (left <-> right)
⌥+← Send Hex Codes: 0x1b 0x66
⌥+→ Send Hex Codes: 0x1b 0x62
and add the following to my ~/.zshrc
bindkey -e
bindkey "^[b" forward-word
bindkey '^[f' backward-word
If you're using iTerm in CSI u mode, the bindings for your .zshrc
end up being:
bindkey '^[[1;3D' backward-word
bindkey '^[[1;3C' forward-word
Though not strictly answering your question, the default binding for forward-word
and backward-word
are alt-f
resp. alt-b
.
This works everywhere, does not require you to leave the home row, and has a nice mnemonic property (f=forward, b=back), while also being consistent with ctrl-f
and ctrl-b
being forward-character
and backward-character
.
Rip out your arrow keys!
On MacOS High Siera 10.13.6 or Mojave 10.14.2 and using iTerm2 with ZSH To move from words I have to put like this:
bindkey "\e\e[D" backward-word
bindkey "\e\e[C" forward-word
Another solutions doesn't work fo rme
If you want iTerminal to respect Emacs style shortcuts like ^Mf and ^Mb for forward/back a word I found best way to use this tip:
Making iTerm to translate 'meta-key' in the same way as in other OSes