68

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.

riskio
  • 971

7 Answers7

126

FWIW, this is what worked on my environment (rhel5.x) using zsh's default.

bindkey "^[[1;5C" forward-word
bindkey "^[[1;5D" backward-word
Goncalo
  • 1,376
23

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.

Pablo A
  • 2,712
Torxed
  • 3,637
  • 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
    please read the question is there.. – riskio Dec 19 '12 at 12:17
  • 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
  • bottom part works for ubuntu 19.10 – Kokizzu Jan 10 '20 at 07:31
  • +1 for the cat > /dev/null trick to see your key sequence. – esmit Oct 05 '23 at 06:42
12

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.

miyalys
  • 224
  • 1
    Did 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
  • 1
    I 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
  • 1
    Thanks, the later bindkey commands did the trick with Zsh in Alacritty. – MetalGodwin Apr 02 '22 at 14:29
  • mblakesley: Maybe it could be due to .inputrc then? – miyalys Apr 03 '22 at 15:09
  • MetalGodwin: Glad to hear it - added it to the list. – miyalys Apr 03 '22 at 15:09
6

Terminal used: Konsole.

To solve: Right click on terminal (or settings in menubar) -> Change current profile > Keyboard mapping -> Change to Default (xfree4)

Pablo A
  • 2,712
riskio
  • 971
3

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

0

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.

macieksk
  • 121
0

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