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.
6 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
-
13
-
2Confirmed, Goncalo's proposal works also in Debian 8.5. I just wonder why this code is not built-in in
.zshrc
by default. Dec 25, 2016 at 9:48 -
1In case anyone wants to use
$terminfo
instead of the escape sequences: the keys$terminfo[kLFT5]
and$terminfo[kRIT5]
worked for me– Gerrit-KJan 22, 2019 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 BNov 29, 2020 at 1:48
-
2It's interesting that
"^[[1;5C"
and"^[[1;5D"
work well directly on my mac 10.15.5– ChironDec 8, 2020 at 3:11
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...– riskioDec 19, 2012 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?– TorxedDec 19, 2012 at 12:01
-
1
-
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.– TorxedDec 25, 2016 at 9: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.– TorxedDec 25, 2016 at 10:01
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.
-
1Did you try the CTRL-V suggestion? Maybe your terminal interprets the keystrokes differently, so the key needs to be bound to different "symbols"?– miyalysDec 25, 2016 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.– miyalysDec 26, 2016 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 BNov 29, 2020 at 1:41 -
1Thanks, the later bindkey commands did the trick with Zsh in Alacritty. Apr 2, 2022 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
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.