1

I've configured tmux so that ctrl+shift+left/right arrow moves windows left/right in their numerical arrangement.

I.e.:

# ~/.tmux.conf
...
bind-key -n C-S-Left swap-window -t -1
bind-key -n C-S-Right swap-window -t +1
...

This works fine when I'm physically at the PC where tmux is running, but does not work when I ssh to the PC using MobaXterm.

I assume that because this works when I am physically at the PC, this indicates a problem with a MobaXterm setting - is there something I can set so that ctrl+shift+left/right arrow are "recognized" the same way across MobaXterm's ssh session as they are through a directly-connected keyboard?

I have tried the accepted answer to this question - it did not work. That question is not quite identical, though: it was about ctrl+arrow, not ctrl+shift+arrow, so perhaps some slight tweak is needed to that accepted answer, but the syntax of the line is obtuse to me - I can't see how it would need to be modified to support ctrl+shift+arrow instead of ctrl+arrow (if it is even what's needed).

$ tmux -V
tmux 2.9a

1 Answer 1

2

If you run cat outside tmux in MobaXterm, then press C-S-Left, what do you see? Is it different from when you press C-Left or press Left without any modifier keys?

IF it is different for all three, you can configure them. If not you can only configure the ones that are unique.

You can change them in terminal-overrides, kRIT5 is C-Right, kLFT5 is C-Left, kUP5 is C-Up, kDN5 is C-Down. For C-S-Right use kRIT6, kLFT6 and so on. The numbers are:

       3       Alt
       4       Shift + Alt
       5       Control
       6       Shift + Control
       7       Alt + Control
       8       Shift + Alt + Control

S-Left is plain kLFT - no number - and same for S-Right (kRIT) and so on.

So for C-S-Left you want kLFT6, kRIT6, kUP6, kDN6.

For example for C-S-Left you might see (you won't see this because if you did it would be working, but this is an example):

^[[1;6D

As I said above, make sure this is unique, many terminals do not support all modifiers.

^[ is Escape, so it goes into terminal-overrides as \E.

terminal-overrides is a set of comma-separated entries. Each entry is a colon-separated list of capabilities. The first is a pattern to match against TERM.

You will need to make sure MobaXterm is using a different TERM than your local computer or you will end up overriding the local terminal too. If both are using xterm, try making MobaXterm xterm-color or something instead, or copy xterm by doing infocmp -x xterm >copy then editing copy to change the name at the start (second line before the |) and installing it again with tic -x copy. Obviously you will need to configure MobaXterm to set this different TERM (or do it in your shell profile based on eg SSH_CONNECTION or something).

Then you can add them in terminal-overrides like this:

set -as terminal-overrides ',myxterm:kLFT6=\E[1;6D:kRIT6=\E[1;6C'

Make sure you restart tmux entirely after changing .tmux.conf, or detach and reattach after changing terminal-overrides from a running tmux.

9
  • This looked promising, but didn't work. As advised, outside tmux in MobaXterm, Left gives ^[[D, C-Left gives ^[[1;5D, and C-S-Left gives ^[OD. So the three are distinct. Based on this and your notes, I added the line set -as terminal-overrides ',myxterm:kLFT6=\EOD:kRIT6=\EOC' in my ~/.tmux.conf, and restarted tmux, but the C-S-Left/Right keys were still not recognized. Did I understand/implement your answer correctly, or did I mess something up? Or do you have other ideas what might be wrong/how to fix? Thank you.
    – StoneThrow
    Commented Mar 27, 2020 at 22:40
  • Did you create a new terminfo entry called myxterm using infocmp -x/tic -x and set TERM to myxterm in MobaXterm? The myxterm bit of the terminal-overrides example must match TERM outside tmux, this is how tmux knows when to apply these overrides. And since you only want to do that for MobaXterm and not your other terminal, it must be unique to MobaXterm. So you can either create a new one yourself, or use an existing variant of xterm like xterm-color in MobaXterm. Commented Mar 28, 2020 at 9:27
  • My $TERM outside of tmux in MobaXterm was xterm-256color so I tried changing the myxterm to xterm-256color and restarting tmux, but it still didn't work. This feels really close to the right solution, just some little thing I'm missing somewhere. So, c-s-left gives ^[OD and c-s-right gives ^[OC and my entry in .tmux.conf is: set -as terminal-overrides ',xterm-256color:kLFT6=\EOD:kRIT6=\EOC' Do I have that right, or am I glitching somewhere?
    – StoneThrow
    Commented Apr 9, 2020 at 23:43
  • That looks right to me. Check tmux info|grep kLFT6 inside tmux matches \033OD. Also what do you see if you now run cat inside tmux and press C-S-Left? Commented Apr 10, 2020 at 5:18
  • ^[OC is normally Left or C-Left not C-S-Left. If you want tmux to send it as C-S-Left, you may need to remove any other entries for this escape sequence - look at tmux info|grep OC inside tmux, if there are any others (there may be probably kcuf1) then add them to terminal-overrides like this: set -as terminal-overrides ',xterm-256color:kcuf1@'. I suspect your terminal actually only supports two kinds of arrow key, no modifiers (Left) and either S-Left or C-Left. Do all of Left, C-Left, S-Left and C-S-Left send unique sequences when you try them with cat? Commented Apr 10, 2020 at 5:31

You must log in to answer this question.

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