25

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.

44

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

bindkey "^[[1;5C" forward-word
bindkey "^[[1;5D" backward-word
  • 5
    ^[^[[D and ^[^[[C, respectively, for OSX – Jon z May 29 '15 at 14:52
  • 1
    Confirmed, 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 9:48
  • Works like a charm in Ubuntu Artful, thanks! – Konrad Garus Nov 27 '17 at 8:42
  • In case anyone wants to use $terminfo instead of the escape sequences: the keys $terminfo[kLFT5] and $terminfo[kRIT5] worked for me – Griddo Jan 22 at 10:10
14

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
    please read the question is there.. – riskio Dec 19 '12 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 Dec 25 '16 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 Dec 25 '16 at 10:01
5

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. .zshrc), and if using a different shell that shells config on that distro may already handle it.

Here's a few terminal emulator-specific solutions:

urxvt/rxvt-unicode (and maybe others):

bindkey "^[Od" backward-word
bindkey "^[Oc" forward-word

terminator, konsole and 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-leftarrow and CTRL-rightarrow - and put the output for each key combination in between the two quotes.

  • 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
2

Solved.

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 Dec 19 '12 at 21:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.