How can I get control+left arrow to go back one word in iTerm2?
bash
Just add the following to ~/.inputrc
:
"\e[1;5D": backward-word
"\e[1;5C": forward-word
See this archived Wiki post for some more explanation. If you want to use the alt key instead for word-to-word movement (like default OS X behavior), use:
"\e[1;9D": backward-word
"\e[1;9C": forward-word
zsh
zsh by default does not use the readline
library and therefore won't read ~/.inputrc
. To get the same functionality, you could add the following to your ~/.zshrc
– this again would use the alt key:
bindkey -e
bindkey '^[[1;9C' forward-word
bindkey '^[[1;9D' backward-word
See this documentation for more about the built-in zsh line editor (zle).
Why is this? You've set up your profile to use the Xterm defaults:
This is why you'll need to "catch" this sequence and tell readline
what to do.
If the above still doesn't work and you are using OS X 10.9 (Mavericks) or there abouts, you probably need to disable the global Mission Control shortcuts which prevent Control+arrow keys from reaching iTerm, even if Mission Control itself is disabled. You can do so from System Preferences → Keyboard → Shortcuts → Mission Control:
Working solution for zsh. Simple, straightforward, out-of-the-box.
Goto:
⌘, Preferences → Profiles → Keys → Keyboard Behavior
Load Preset:
Natural Text Editing
I fixed it this way:
In top menu; go to
Profiles
-> Open profiles...
-> Edit profiles... (button)
-> Keys (tab)
-> Load Preset... (dropdown)
-> Choose "Natural text editing". Done! :-)