2

I have this in my .inputrc:

"\e[A": history-search-backward
"\e[B": history-search-forward
set show-all-if-ambiguous on
set completion-ignore-case on

# mappings for Ctrl-left-arrow and Ctrl-right-arrow for word moving
"\eOc": forward-word
"\eOd": backward-word
"\e[1;5C": forward-word
"\e[1;5D": backward-word
"\e[5C": forward-word
"\e[5D": backward-word
"\e\e[C": forward-word
"\e\e[D": backward-word

Also, I didn't touch anything in .zprezto/modules/editor/init.zsh, where bindkey instructions are defined.

However, when I press CtrlLeft or CtrlRight my terminal (URxvt) blinks and nothing happens. On the other hand, in XTerm it works. It appears to be a URxvt problem.

rubik
  • 837
  • 2
  • 9
  • 21

2 Answers2

5

The ~/.inputrc file is a bash thing, not a zsh thing as far as I know. It controls the behavior of readline, the zsh equivalent of which is zle. You can modify its behavior using the bindkey command.

So, to get Ctrl Left and Right back, add these lines to your ~/.zshrc (there might be a better place for them, an equivalent to ~/.inputrc but I don't know it and ~/.zshrc works):

bindkey "\eOc" forward-word
bindkey "\eOd" backward-word
bindkey "\e[1;5C" forward-word
bindkey "\e[1;5D" backward-word
bindkey "\e[5C" forward-word
bindkey "\e[5D" backward-word
bindkey "\e\e[C" forward-word
bindkey "\e\e[D" backward-word
terdon
  • 234,489
  • 66
  • 447
  • 667
  • Thanks for your help. Unfortunately it still does not work. The terminal just blinks. I also found [this question](http://stackoverflow.com/questions/24158794/in-prezto-how-to-get-ctrl-rarrow-working) on StackOverflow. Neither that helped... – rubik Feb 07 '15 at 16:25
  • @rubik 1) you _are_ using `zsh` right? 2) Did you start a new terminal (or source `.zshrc`) after changing it? 3) Did they work before installing prezto? I mean in `zsh` not in `bash`. 4) URxvt is sometimes strange, does it work in a different terminal emulator? – terdon Feb 07 '15 at 16:30
  • Yes, I tried both methods. Actually I tried with xterm and it works, so it's a URxvt problem! Do you have any suggestions? – rubik Feb 07 '15 at 16:33
  • 1
    @rubik ah, yes, I thought that might be it. The different emulators define key combinations differently. You should be able to find what `Ctrl+Left` sends by typing `Ctrl+V` and then hitting `Ctrl+Left`. That should give you an idea of what code it is looking for. Odd though, it works on `rxvt` on my system, installing `rxvt-unicode` now to check. – terdon Feb 07 '15 at 16:36
  • @rubik it works fine on `urxvt` as well. Are you sure you copied _all_ the lines? Also, you might have a user-specific setting that is screwing things up. Try creating a new user, adding the lines to the user's `~/.zshrc` and testing there. – terdon Feb 07 '15 at 16:39
  • Argh. Actually even with `Ctrl-V` the terminal just blinks! Something must be wrong with my configuration. Will update. – rubik Feb 07 '15 at 16:52
  • 1
    @rubik please edit your question and include the details from these comments. The fact that it works in another terminal is particularly important – terdon Feb 07 '15 at 18:24
1

The key bindings shown are for xterm (and programs which copy xterm's behavior). urxvt is a descendant of rxvt, which uses different key bindings. By default, controlleft for rxvt/urxvt sends escapeOd. You can see this by running

cat -v

and typing that key combination. It will echo as ^[Od. The same issue applies to the other cursor keys.

urxvt provides a resource setting keysym.sym (an extension of a feature introduced in rxvt) which you could use to modify the keys sent by these terminals to more closely match xterm. That would would be a resource setting like this:

URxvt.keysym.Control-0xff51:    \033[1;5D

where (as indicated in the manual page), Control is the modifier, and 0xff51 is the code for the cursor-left key which you can get using xev.

To get all of the keys, you'd have to add a resource for each of the keys (and modifier).

Further reading:

Thomas Dickey
  • 75,040
  • 9
  • 171
  • 268