After the last system update the ctrl + left/right arrow command on zsh terminal doesn't do anything. Also ctrl+ u has something wrong because usually that command erase from the cursor to the beginning of the line, while now erase entire line.. Someone knows how to solve these problems? thank you all.
-
Have you found any acceptable answer? I think Goncalo's answer is great. – Léo Léopold Hertz 준영 Dec 25 '16 at 09:47
7 Answers
FWIW, this is what worked on my environment (rhel5.x) using zsh's default.
bindkey "^[[1;5C" forward-word
bindkey "^[[1;5D" backward-word

- 1,376
-
14
-
2Confirmed, Goncalo's proposal works also in Debian 8.5. I just wonder why this code is not built-in in
.zshrc
by default. – Léo Léopold Hertz 준영 Dec 25 '16 at 09:48 -
-
1In case anyone wants to use
$terminfo
instead of the escape sequences: the keys$terminfo[kLFT5]
and$terminfo[kRIT5]
worked for me – Gerrit-K Jan 22 '19 at 10:10 -
1This works, but why is it necessary? Why isn't this something taken care of via zsh defaults or via common options in the zsh "new user script"? – Mike B Nov 29 '20 at 01:48
-
2It's interesting that
"^[[1;5C"
and"^[[1;5D"
work well directly on my mac 10.15.5 – Chiron Dec 08 '20 at 03:11 -
@Chiron It worked for me as well, BUT i had to disable "Mission Control" under Keyboard->Shortcuts in the System Preferences.
Otherwise it'll intercept ctrl+left ctrl+right to switch between Desktops.
– TesterJeff Apr 07 '21 at 13:39 -
This doesn't work for me at all on zsh in iTerm2 on a recent MacBook Pro. Pressing the keys does nothing. I don't yet know why. – Jonathan Hartley Dec 22 '23 at 18:18
-
Ctrl+U is most likely because you've got the cursor at the end of the line. Secondly, which version of Gentoo are you referring to as the "last system update"?
And what would you like the ctrl+left/right to do?
Add to zsh config:
bindkey '^[[1;5C' emacs-forward-word bindkey '^[^[[D' emacs-backward-word
And from old scrap i found (might help):
bindkey ";5C" forward-word bindkey ";5D" backward-word
or have a look at this link, which should help you out?
Note: If the config works but the supposed keys doesn't do what you want it's perhaps because the key-definition differs from yours and mine, do:
cat > /dev/null
and press the keys you'd like to get outputted and adjust accordingly.
-
1"Ctrl+U is most likely because you've got the cursor at the end of the line" of course i mean when my cursor is in the middle."And what would you like the ctrl+left/right to do?" usually ctrl+left arrow : skip word going left etc... – riskio Dec 19 '12 at 11:53
-
And which shell/terminal are you using? Makre sure you use Emacs or whatever terminal you usually use and /bin/bash? are you running through screen? – Torxed Dec 19 '12 at 12:01
-
1
-
Sorry, missed that part. Added a _possible__ solution, not sure if that helps you out tho but might. – Torxed Dec 19 '12 at 12:45
-
Ctrl+U is bound to
kill-whole-line
by default.bindkey "^U" backward-kill-line
should yield the desired behaviour. – DaSourcerer Nov 28 '16 at 18:27 -
1@Masi Not sure, I answered two years before him and our answers are almost identical, I just showed two different ways to do it.. and you can merge them both to combine what he wrote. – Torxed Dec 25 '16 at 09:54
-
1@Masi All I know is that back then (remember, 2010-2012.. It was a long time ago) these two (and it's combination) worked for me on many different systems. I was on both Unix and Linux (and he was on Gentoo, a rolling release OS). And there's still traces of this on a lot of examples.. Such as this repository. Now, again, I'm not quite sure as to why but it worked on at least two machines so I thought I'd share it. And sure his is more clear TODAY, and I don't mind him getting all the up votes. This is a legacy post. – Torxed Dec 25 '16 at 10:01
-
+1 for ";5C" and ";5D", working in RedHat 6 when other solutions didn't – andrew lorien Jun 21 '17 at 07:29
-
-
What works doesn't directly depend on the distro (Gentoo, Debian, RHEL etc.) or the shell (ZSH, KSH, BASH) - it depends on which terminal emulator
is used, and its settings: konsole, terminator, urxvt, lx-terminal etc. The distro may matter if it uses a different standard shell config (fx. .bashrc
, .zshrc
, .inputrc
), and if using a different shell that shells config on that distro may already handle it.
Here are a few terminal emulator-specific solutions:
urxvt/rxvt-unicode (and maybe others):
bindkey "^[Od" backward-word
bindkey "^[Oc" forward-word
alacritty, konsole, terminator, xterm (and maybe others):
bindkey "^[[1;5D" backward-word
bindkey "^[[1;5C" forward-word
For a more general approach you start your terminal, press Ctrl + V followed by the key combination you want the escape code (the name) of - in this case the key combinations Ctrl + Left Arrow and Ctrl + Right Arrow - and put the output for each key combination in between the two quotes to make a keybind for it.

- 224
-
1Did you try the CTRL-V suggestion? Maybe your terminal interprets the keystrokes differently, so the key needs to be bound to different "symbols"? – miyalys Dec 25 '16 at 14:16
-
1I updated my answer. There are multiple solutions depending on the
terminal emulator
used. The distro or shell doesn't matter. That's probably also why it's not in .zshrc, because what works for one terminal emulator doesn't work for another. But that could probably be solved if zshrc fx. read the $TERM environment variable and applied different bindkey settings based on the result. – miyalys Dec 26 '16 at 12:46 -
This sounds correct, yet on my Mint (Ubuntu), bash is fine, while zsh is not. The user or system level .bashrc don't show
keybind
anywhere, so not sure why the difference. – Mike B Nov 29 '20 at 01:41 -
1Thanks, the later bindkey commands did the trick with Zsh in Alacritty. – MetalGodwin Apr 02 '22 at 14:29
-
-
Terminal used: Konsole.
To solve: Right click on terminal (or settings in menubar) -> Change current profile > Keyboard mapping -> Change to Default (xfree4)
I came across this because I was having similar issues on a macbook using external keyboard.
Turns out ctrl+Left and ctrl+Right are set as Keyboard shortcuts for mission control.
Disabling this on the system fixed my issue
Adding
bindkey '\e\e[C' forward-word
bindkey '\e\e[D' backward-word
Enabled alt+right and alt+left to do the same thing

- 31
Fixing this in Konsole: set Right-Ctrl
and Left-Ctrl
mappings same as they're in Default(XFree_4): \E[1;5D
and \E[1;5C
accordingly.

- 121
I faced this issue when I create ~/.inputrc
file with:
"\e[A": history-search-backward
"\e[B": history-search-forward
context.so, I solved this issue by change it to below:
"\e[A": history-search-backward
"\e[B": history-search-forward
"\e[1;5D": backward-word
"\e[1;5C": forward-word

- 746