Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bind Ctrl+Tab and Ctrl+Shift+Tab in tmux

I'm trying to a get a ctrl+tab and ctrl+shift+tab binding to work inside of a tmux session (I'm also using PuTTY).

I already went through the pains of having to recompile PuTTY so it would send ctrl and shift correctly. After using ctrl+v, and I'm able to see that ^[[27;5;9~ and ^[[27;6;9~ are being sent for ctrl+tab and ctrl+shift+tab, respectively. Is there any way I can get these bound to next-window and previous-window inside of tmux?

Edit: After some research, I'm thinking I might have to configure xterm to include those keycodes. Any idea how I would go about doing that?

Edit2: So I found out I can retrieve infocmp and recompile it. I added

kctab=\E[27;5;9~, kcstab=\E[27;6;9~,

to the end of it, except now it's giving me an error. "entry does not start with terminal names in column one"

like image 772
dook Avatar asked Mar 18 '13 04:03

dook


People also ask

How do I change Ctrl-B to tmux?

The first command unbind C-b removes the current Ctrl-b binding, the second command set-option -g prefix C-a set Ctrl-a as the main tmux command binding.


1 Answers

Recent “unreleased” versions of tmux do automatically recognize those xterm-style key sequences once you have your terminal sending them (no need to change your terminfo entry). The next release version (1.8?) should also have this support. With an appropriate build of tmux1, all you have to do is bind the keys in your tmux configuration:

bind-key C-Tab next-window bind-key C-S-Tab previous-window 

You will still need to type your prefix key before these keys.

(Note: ~/.tmux.conf is only processed when the server starts. If you make changes to it, you will either need to exit all your sessions and restart the server, or use (e.g.) tmux source ~/.tmux.conf to have your existing server re-process the file.)

Also, if you want tmux to pass along these (and other) xterm-style key sequences to programs running inside tmux, then you will need to enable the xterm-keys window option.

set-option -gw xterm-keys on 

(If you prefer, you can do this on a per-window basis by using -w instead of -gw.)


If you want to be able to use those keys without typing the prefix, then you can use “no prefix” bindings instead:

bind-key -n C-Tab next-window bind-key -n C-S-Tab previous-window 

This will more or less “dedicate” the keys to tmux, though. It will be difficult to type these keys to any program running inside tmux (e.g. you would have to use the tmux command send-keys C-Tab—as normal, xterm-keys must be enabled to send these xterm-style key sequences).


The problem with your terminfo entry editing is probably because each line after the one that names the terminal type needs to start with a Tab. Lines that do not start with a tab are the beginning of a new terminal entry. Technically, the NL TAB sequence is basically a line continuation in this file format; each entry is a single logical line.

Also, if you are redefining terminfo entries, be sure to use -x with infocmp and tic to preserve the user-defined capabilities (some of which are fairly standard).


1 I.e. built from recent code in the tmux Git repository at sf.net (at the clone-able URL git://git.code.sf.net/p/tmux/tmux-code).

like image 91
Chris Johnsen Avatar answered Sep 22 '22 17:09

Chris Johnsen