Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bindings with key sequences

Does Tmux supports key-bindings with key sequences like Vim does (e.g. bind-key ab kill-pane)? Or how can i emulate that?

like image 923
xged Avatar asked Aug 13 '14 19:08

xged


1 Answers

I'm using tmux 2.3.

You can emulate key sequences by defining your own key tables and chaining them together.

For example, if I want <C-q>x to do something, I put the binding for 'x' into a key table "my-keys", then bind the key that activates that key table with switch-client (C-q):

bind-key -Tmy-keys x send-keys "my binding"

# Multi-key prefix for custom bindings
bind-key -Troot C-q switch-client -Tmy-keys

NOTE: I started with C-q, because it seems to conflict the least with the command line and Vim.

So, now you have every key at your disposal with a C-q prefix.

If you want more keys in your sequence, add another level of indirection:

bind-key -Tmy-keys x send-keys "my binding"

# Pane (i.e. 'W'indow commands like Vim with C-w)
bind-key -Tmy-keys-window-ctl s swap-pane
bind-key -Tmy-keys C-w switch-client -T my-keys-window-ctl

# Multi-key prefix for custom bindings
bind-key -Troot C-q switch-client -Tmy-keys

So, now I have swap-pane bound to <C-q><C-w>s.

This works because

  1. <C-q> activates "my-keys" key table,
  2. which has the binding <C-w>,
  3. which activates "my-keys-window-ctl" key table
  4. which has the binding s to call swap-pane
like image 192
Droj Avatar answered Nov 11 '22 19:11

Droj