3

I am attempting customize tmux so that

  • Ctrl-Arrows are used for pane selection
  • Shift-Arrows are used for pane resizing
  • Alt-Arrows (left, right) are used for window selection

... all are working correctly, except for Shift-Up and Shift-Down. (Puzzlingly, Shift-Left and Shift-Right work as expected.)

This is running tmux 2.0 inside xfce4-terminal (although I've also seen this problem on Ubuntu, using Ubuntu's default terminal program.)

Is there something I am not doing correctly? Here is the entire contents of my .tmux.conf file:

# split <h>orizontal and <v>ertical
bind-key h split-window -v
bind-key v split-window -h

# Use Ctrl-arrow keys without prefix key to switch panes
bind -n C-Up    select-pane -U
bind -n C-Down  select-pane -D
bind -n C-Left  select-pane -L
bind -n C-Right select-pane -R

# Use Shift-arrow keys without prefix key to resize panes
bind -n S-Up    resize-pane -U
bind -n S-Down  resize-pane -D
bind -n S-Left  resize-pane -L
bind -n S-Right resize-pane -R

# Use Alt-arrow keys without prefix key to switch windows
bind -n M-Left  previous-window
bind -n M-Right next-window

# No delay for escape key press
set -sg escape-time 0

# Reload tmux config
bind-key r source-file ~/.config/.tmux.conf \; display-message "Configuration reloaded"
1
  • NOTE: I just tried this with xterm as my terminal app, but with the same results. Commented May 8, 2015 at 6:11

1 Answer 1

3

The problem is unlikely to be related to some difference in application mode versus normal mode, because xterm sends the same sequence of characters for shifted and unshifted cursor keys.

One clue to the problem is that the various ctrl items are all extended xterm capabilities. tmux uses a couple of tables:

  • one lists special keys which are unlikely to be found in a terminal entry
  • the other lists terminal capabilities which might be gotten from a regular terminal database entry.

For the latter, these rows from tmux's table are relevant:

    { TTYC_KDN2, TTYCODE_STRING, "kDN" },
    { TTYC_KDN3, TTYCODE_STRING, "kDN3" },
    { TTYC_KDN4, TTYCODE_STRING, "kDN4" },
    { TTYC_KDN5, TTYCODE_STRING, "kDN5" },
    { TTYC_KDN6, TTYCODE_STRING, "kDN6" },
    { TTYC_KDN7, TTYCODE_STRING, "kDN7" },
    { TTYC_KEND, TTYCODE_STRING, "kend" },

    { TTYC_KLFT2, TTYCODE_STRING, "kLFT" },
    { TTYC_KLFT3, TTYCODE_STRING, "kLFT3" },
    { TTYC_KLFT4, TTYCODE_STRING, "kLFT4" },
    { TTYC_KLFT5, TTYCODE_STRING, "kLFT5" },
    { TTYC_KLFT6, TTYCODE_STRING, "kLFT6" },
    { TTYC_KLFT7, TTYCODE_STRING, "kLFT7" },

    { TTYC_KRIT2, TTYCODE_STRING, "kRIT" },
    { TTYC_KRIT3, TTYCODE_STRING, "kRIT3" },
    { TTYC_KRIT4, TTYCODE_STRING, "kRIT4" },
    { TTYC_KRIT5, TTYCODE_STRING, "kRIT5" },
    { TTYC_KRIT6, TTYCODE_STRING, "kRIT6" },
    { TTYC_KRIT7, TTYCODE_STRING, "kRIT7" },
    { TTYC_KUP2, TTYCODE_STRING, "kUP" },
    { TTYC_KUP3, TTYCODE_STRING, "kUP3" },
    { TTYC_KUP4, TTYCODE_STRING, "kUP4" },
    { TTYC_KUP5, TTYCODE_STRING, "kUP5" },
    { TTYC_KUP6, TTYCODE_STRING, "kUP6" },
    { TTYC_KUP7, TTYCODE_STRING, "kUP7" },

    { TTYC_RI, TTYCODE_STRING, "ri" },

Most of these rows (in tty-term.c) are xterm extensions. The strings for the shifted cursor keys might be provided by "kUP", "kDN", "kLFT", "kRGT" — as well as "kri" and "kind".

The last two are problematic:

  • tmux has a table entry for "ri" (the string sent to the terminal) but none for "kri" and "kind" (your up/down cursor-keys)
  • because (n)curses' wgetch will see only the first capability with a given value in the list of strings, ncurses' database defines only one possibility.
  • kUP and kDN are extensions, not standard capabilities, so ncurses defines "kri" and "kind", which are standard.

The problem is not with your configuration, but a simple bug in tmux which could be addressed by adding entries to that table. Something like this (untested) is a way to proceed:

    { TTYC_KUP2, TTYCODE_STRING, "kri" },
    { TTYC_KDN2, TTYCODE_STRING, "kind" },
5
  • Thank you for such a definitive answer! I will attempt to recompile tmux with those lines added, and see what the results are. One additional counterpoint: I had forgotten about this, but I do not see this problem when I use the 'Secure Shell' ChromeOS app as my remote terminal. How does that observation jive with your answer? Commented May 8, 2015 at 18:29
  • Note that replacing the existing KUP2 and KDN2 rows with your variants seemed to have no effect on the problem. Commented May 8, 2015 at 19:08
  • Later, when I have more time, I may attempt to watch tmux's reactions to these keypresses in a debugger. Commented May 8, 2015 at 19:10
  • Sounds as if the problem is deeper (though if I did not misread the source, the detail that I pointed out is likely part of the solution). Knowing the actual TERM and terminal description (output of infocmp might help). Commented May 8, 2015 at 23:44
  • I agree; the problem does seem to be deeper. Basically, every terminal program I use behaves slightly differently in this respect. It will not work correctly at the console, or using PuTTY for ssh, but it will work correctly with old-fashioned xterm. I'll update my question with TERM (for each of the above) and infocmp details after I experiment a little more. Commented Jun 7, 2015 at 4:21

You must log in to answer this question.

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