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 준영– Léo Léopold Hertz 준영2016-12-25 09:47:58 +00:00Commented Dec 25, 2016 at 9:47
-
This differs by the terminal. I just posted an answer that shows you how to figure out which code your terminal uses.Adam Katz– Adam Katz2024-07-19 21:53:11 +00:00Commented Jul 19, 2024 at 21:53
8 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
-
15
^[^[[Dand^[^[[C, respectively, for OSXjrz– jrz2015-05-29 14:52:41 +00:00Commented May 29, 2015 at 14:52 -
2Confirmed, Goncalo's proposal works also in Debian 8.5. I just wonder why this code is not built-in in
.zshrcby default.Léo Léopold Hertz 준영– Léo Léopold Hertz 준영2016-12-25 09:48:36 +00:00Commented Dec 25, 2016 at 9:48 -
1In case anyone wants to use
$terminfoinstead of the escape sequences: the keys$terminfo[kLFT5]and$terminfo[kRIT5]worked for meGerrit-K– Gerrit-K2019-01-22 10:10:30 +00:00Commented Jan 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 B– Mike B2020-11-29 01:48:29 +00:00Commented Nov 29, 2020 at 1:48
-
2It's interesting that
"^[[1;5C"and"^[[1;5D"work well directly on my mac 10.15.5Chiron– Chiron2020-12-08 03:11:44 +00:00Commented Dec 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-wordAnd from old scrap i found (might help):
bindkey ";5C" forward-word bindkey ";5D" backward-wordor 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– riskio2012-12-19 11:53:30 +00:00Commented Dec 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?Torxed– Torxed2012-12-19 12:01:43 +00:00Commented Dec 19, 2012 at 12:01
-
1please read the question is there..riskio– riskio2012-12-19 12:17:33 +00:00Commented Dec 19, 2012 at 12:17
-
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– Torxed2016-12-25 09:54:28 +00:00Commented Dec 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.Torxed– Torxed2016-12-25 10:01:01 +00:00Commented Dec 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"?miyalys– miyalys2016-12-25 14:16:51 +00:00Commented Dec 25, 2016 at 14:16
-
1I updated my answer. There are multiple solutions depending on the
terminal emulatorused. 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– miyalys2016-12-26 12:46:14 +00:00Commented Dec 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
keybindanywhere, so not sure why the difference.Mike B– Mike B2020-11-29 01:41:32 +00:00Commented Nov 29, 2020 at 1:41 -
1Thanks, the later bindkey commands did the trick with Zsh in Alacritty.MetalGodwin– MetalGodwin2022-04-02 14:29:15 +00:00Commented Apr 2, 2022 at 14:29
-
mblakesley: Maybe it could be due to
.inputrcthen?miyalys– miyalys2022-04-03 15:09:04 +00:00Commented Apr 3, 2022 at 15:09
Terminal used: Konsole.
To solve: Right click on terminal (or settings in menubar) -> Change current profile > Keyboard mapping -> Change to Default (xfree4)
-
not even really related to zsh but sure, a fix is a fix.Torxed– Torxed2012-12-19 21:05:57 +00:00Commented Dec 19, 2012 at 21:05
-
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
-
Thank you disabling Keyboard shortcuts for mission control worked for mekachi_dk– kachi_dk2024-07-16 20:09:07 +00:00Commented Jul 16, 2024 at 20:09
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.
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
There are a lot of different solutions to this question and users must match them to their terminal, as that's where the differences come from. Also note that screen, tmux, and others are yet another variable. I wish I had better documented which terminal each of my bindkey commands refers to...
The best way to figure this out is by seeing it for yourself. The showkey command that ships with the kbd package (at least on .deb and .rpm systems) is a great way to do this. Otherwise, cat works pretty well as long as you precede your key sequences with Ctrl+v to ensure they're taken literally. Consider a line break between sequences so its easier to tease apart later.
This is run from xfce4-terminal 1.1.3 with Debian's xbd 2.6.4-2.
Within showkey -a, I typed Ctrl+← then Ctrl+→ then Ctrl+u then Ctrl+d to exit:
$ showkey -a
Press any keys - Ctrl-D will terminate this program
^[[1;5D 27 0033 0x1b
91 0133 0x5b
49 0061 0x31
59 0073 0x3b
53 0065 0x35
68 0104 0x44
^[[1;5C 27 0033 0x1b
91 0133 0x5b
49 0061 0x31
59 0073 0x3b
53 0065 0x35
67 0103 0x43
^U 21 0025 0x15
^D 4 0004 0x04
That means I can run:
bindkey '^[[1;5D' backward-word
bindkey '^[[1;5C' forward-word
bindkey '^U' kill-region
kill-region replaces kill-whole-line to replicate bash's functionality and only removes the text to the left of the cursor (the output of bindkey without arguments will show you all current bindings).