3

I've configured tmux to skip words on Ctrl+right / left :

set-window-option -g xterm-keys on

It works just fine, but as I do SSH, it doesn't work and prints ;5D or ;5C..

The same issue occurred when I used screen, is there some specific configuration for tmux/screen on SSH ?

1

1 Answer 1

6

It's not tmux nor screen that "skips words"; the text input is provided by your shell. You must therefore find out what key sequence Ctrl+arrows generate, and teach your shell that it means "skip a word". Otherwise, it will stop interpreting mid-sequence because it's not recognized.

If you're using bash, it takes some of the key definitions from ncurses/terminfo, and others from the "inputrc" file. So first make sure you have the ncurses terminal definitions installed ("ncurses-term" or similar). And if you have a custom ~/.inputrc, tell it to import the system-wide one, using:

$include /etc/inputrc

If that doesn't help, add a custom mapping to your ~/.inputrc file (on the server, of course):

  1. In bash, press CtrlV (the "verbatim input" key), followed by Ctrl. You'll see the "Ctrl+right" escape sequence inserted as plain text:

    ^[[1;5C
    

    The ^[ means an "ESC" character; the rest are plain text. So this is ESC [ 1 ; 5 C.

  2. In man bash, find the inputrc ("readline") command for skipping a word. (It's forward-word.)

  3. In ~/.inputrc, add both the key sequence and the command. (The "ESC" is written as \e.)

    "\e[1;5C": forward-word
    
  4. Repeat the same for Ctrl.

  5. Close ssh, then connect again and see if it works.

Note that most distributions already have these particular mappings in /etc/inputrc.

5
  • I can't edit anything on the server itself. Adding "\e[1;5C": forward-word to ` ~/.inputrc` (on my system) doesn't help.
    – SagiLow
    Commented Feb 26, 2015 at 13:04
  • 1
    @SagiLow: Of course it doesn't help – the server can't see what files the client has... There's really nothing the client could do to fix this, anyway. Commented Feb 27, 2015 at 13:35
  • my colleagues who uses Ubuntu 12 manage to this this just fine, even when connecting to the same remote system. I don't think it cannot be done
    – SagiLow
    Commented Mar 1, 2015 at 8:11
  • bash uses none of the extended key-definitions from the terminal database (such as the "ctrl+arrow" in the question). For that, it relies exclusively on the user's .inputrc file. Commented Apr 28, 2015 at 0:17
  • And, strictly speaking, .inputrc and command names, line editing and history belong to GNU readline, not bash. (Only do not make a CLISP mistake: it's GPL, not LGPL. For non-GPL programs, there is libedit). Commented Jul 27, 2021 at 22:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .