Coverage Report

Created: 2026-07-16 06:55

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/tmux/key-bindings.c
Line
Count
Source
1
/* $OpenBSD: key-bindings.c,v 1.189 2026/07/15 10:38:31 nicm Exp $ */
2
3
/*
4
 * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
5
 *
6
 * Permission to use, copy, modify, and distribute this software for any
7
 * purpose with or without fee is hereby granted, provided that the above
8
 * copyright notice and this permission notice appear in all copies.
9
 *
10
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15
 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16
 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
 */
18
19
#include <sys/types.h>
20
21
#include <ctype.h>
22
#include <stdlib.h>
23
#include <string.h>
24
25
#include "tmux.h"
26
27
#define DEFAULT_SESSION_MENU \
28
  " #{S/t:#{?#{&&:#{<:#{loop_index},6},#{!:#{session_active}}},'Switch To #[underscore]#{session_name}' '' {switch-client -t=#{session_id}#} ,}}" \
29
  " ''" \
30
  " 'Renumber' 'N' {move-window -r}" \
31
  " 'Rename' 'r' {command-prompt -I '#S' {rename-session -- '%%'}}" \
32
  " 'Detach' 'd' {detach-client}" \
33
  " ''" \
34
  " 'New Session' 's' {new-session}" \
35
  " 'New Window' 'w' {new-window}"
36
#define DEFAULT_WINDOW_MENU \
37
  " '#{?#{>:#{session_windows},1},,-}Swap Left' 'l' {swap-window -t:-1}" \
38
  " '#{?#{>:#{session_windows},1},,-}Swap Right' 'r' {swap-window -t:+1}" \
39
  " '#{?pane_marked_set,,-}Swap Marked' 's' {swap-window}" \
40
  " ''" \
41
  " 'Kill' 'X' {kill-window}" \
42
  " 'Respawn' 'R' {respawn-window -k}" \
43
  " '#{?pane_marked,Unmark,Mark}' 'm' {select-pane -m}" \
44
  " 'Rename' 'n' {command-prompt -FI \"#W\" {rename-window -t '#{window_id}' -- '%%'}}" \
45
  " ''" \
46
  " 'New After' 'w' {new-window -a}" \
47
  " 'New At End' 'W' {new-window}"
48
#define DEFAULT_PANE_MENU \
49
  " '#{?#{m/r:(copy|view)-mode,#{pane_mode}},Go To Top,}' '<' {send -X history-top}" \
50
  " '#{?#{m/r:(copy|view)-mode,#{pane_mode}},Go To Bottom,}' '>' {send -X history-bottom}" \
51
  " ''" \
52
  " '#{?#{==:#{pane_mode},copy-mode},#{?copy_line_numbers,Hide Line Numbers,Show Line Numbers},}' 'L' {send -X line-numbers-toggle}" \
53
  " '#{?#{==:#{pane_mode},copy-mode},#{?refresh_active,Refresh Off,Refresh On},}' 'r' {send -X refresh-toggle}" \
54
  " ''" \
55
  " '#{?#{&&:#{buffer_size},#{!:#{pane_in_mode}}},Paste #[underscore]#{=/9/...:buffer_sample},}' 'p' {paste-buffer}" \
56
  " ''" \
57
  " '#{?mouse_word,Search For #[underscore]#{=/9/...:mouse_word},}' 'C-r' {if -F '#{?#{m/r:(copy|view)-mode,#{pane_mode}},0,1}' 'copy-mode -t='; send -Xt= search-backward -- \"#{q:mouse_word}\"}" \
58
  " '#{?mouse_word,Type #[underscore]#{=/9/...:mouse_word},}' 'C-y' {copy-mode -q; send-keys -l -- \"#{q:mouse_word}\"}" \
59
  " '#{?mouse_word,Copy #[underscore]#{=/9/...:mouse_word},}' 'c' {copy-mode -q; set-buffer -- \"#{q:mouse_word}\"}" \
60
  " '#{?mouse_line,Copy Line,}' 'l' {copy-mode -q; set-buffer -- \"#{q:mouse_line}\"}" \
61
  " ''" \
62
  " '#{?mouse_hyperlink,Type #[underscore]#{=/9/...:mouse_hyperlink},}' 'C-h' {copy-mode -q; send-keys -l -- \"#{q:mouse_hyperlink}\"}" \
63
  " '#{?mouse_hyperlink,Copy #[underscore]#{=/9/...:mouse_hyperlink},}' 'h' {copy-mode -q; set-buffer -- \"#{q:mouse_hyperlink}\"}" \
64
  " ''" \
65
  " '#{?#{#{pane_floating_flag}},Move,}' '' {display-menu -xL -yL -T '#[align=centre]Move' " DEFAULT_MOVE_MENU " }" \
66
  " '#{?#{#{pane_floating_flag}},Move & Resize,}' '' {display-menu -xL -yL -T '#[align=centre]Move & Resize' " DEFAULT_MOVE_RESIZE_MENU " }" \
67
  " '#{?#{#{pane_floating_flag}},Tile,}' 't' { join-pane }" \
68
  " '#{?#{!:#{pane_floating_flag}},Float,}' 'f' { break-pane -W }" \
69
  " '#{?#{!:#{pane_floating_flag}},Horizontal Split,}' 'h' {split-window -h}" \
70
  " '#{?#{!:#{pane_floating_flag}},Vertical Split,}' 'v' {split-window -v}" \
71
  " ''" \
72
  " '#{?#{&&:#{!:#{pane_floating_flag}},#{>:#{window_panes},1}},Swap Up,}' 'u' {swap-pane -U}" \
73
  " '#{?#{&&:#{!:#{pane_floating_flag}},#{>:#{window_panes},1}},Swap Down,}' 'd' {swap-pane -D}" \
74
  " '#{?pane_marked_set,,-}Swap Marked' 's' {swap-pane}" \
75
  " ''" \
76
  " 'Kill' 'X' {kill-pane}" \
77
  " 'Respawn' 'R' {respawn-pane -k}" \
78
  " '#{?pane_marked,Unmark,Mark}' 'm' {select-pane -m}" \
79
  " '#{?#{>:#{window_panes},1},,-}#{?window_zoomed_flag,Unzoom,Zoom}' 'z' {resize-pane -Z}"
80
#define DEFAULT_MOVE_MENU \
81
  " 'Centre' 'c' {move-pane -P centre}" \
82
  " ''" \
83
  " 'Top Left' '1' {move-pane -P top-left}" \
84
  " 'Top Right' '2' {move-pane -P top-right}" \
85
  " 'Bottom Left' '3' {move-pane -P bottom-left}" \
86
  " 'Bottom Right' '4' {move-pane -P bottom-right}" \
87
  " ''" \
88
  " 'Top' 't' {move-pane -P top-centre}" \
89
  " 'Bottom' 'b' {move-pane -P bottom-centre}" \
90
  " 'Left' 'l' {move-pane -P centre-left}" \
91
  " 'Right' 'r' {move-pane -P centre-right}"
92
#define DEFAULT_MOVE_RESIZE_MENU \
93
  " 'Fill' '0' {resize-pane -x100% -y100%; move-pane -P top-left}" \
94
  " ''" \
95
  " 'Top Left' '1' {resize-pane -x50% -y50%; move-pane -P top-left}" \
96
  " 'Top Right' '2' {resize-pane -x50% -y50%; move-pane -P top-right}" \
97
  " 'Bottom Left' '3' {resize-pane -x50% -y50%; move-pane -P bottom-left}" \
98
  " 'Bottom Right' '4' {resize-pane -x50% -y50%; move-pane -P bottom-right}" \
99
  " ''" \
100
  " 'Top' 't' {resize-pane -x100% -y50%; move-pane -P top-centre}" \
101
  " 'Bottom' 'b' {resize-pane -x100% -y50%; move-pane -P bottom-centre}" \
102
  " 'Left' 'l' {resize-pane -x50% -y100%; move-pane -P centre-left}" \
103
  " 'Right' 'r' {resize-pane -x50% -y100%; move-pane -P centre-right}"
104
105
static int key_bindings_cmp(struct key_binding *, struct key_binding *);
106
0
RB_GENERATE_STATIC(key_bindings, key_binding, entry, key_bindings_cmp);
Unexecuted instantiation: key-bindings.c:key_bindings_RB_MINMAX
Unexecuted instantiation: key-bindings.c:key_bindings_RB_REMOVE
Unexecuted instantiation: key-bindings.c:key_bindings_RB_REMOVE_COLOR
Unexecuted instantiation: key-bindings.c:key_bindings_RB_FIND
Unexecuted instantiation: key-bindings.c:key_bindings_RB_INSERT
107
0
static int key_table_cmp(struct key_table *, struct key_table *);
108
0
RB_GENERATE_STATIC(key_tables, key_table, entry, key_table_cmp);
Unexecuted instantiation: key-bindings.c:key_tables_RB_FIND
Unexecuted instantiation: key-bindings.c:key_tables_RB_INSERT
Unexecuted instantiation: key-bindings.c:key_tables_RB_MINMAX
Unexecuted instantiation: key-bindings.c:key_tables_RB_REMOVE
Unexecuted instantiation: key-bindings.c:key_tables_RB_REMOVE_COLOR
109
0
static struct key_tables key_tables = RB_INITIALIZER(&key_tables);
110
0
111
0
static int
112
0
key_table_cmp(struct key_table *table1, struct key_table *table2)
113
0
{
114
0
  return (strcmp(table1->name, table2->name));
115
0
}
116
117
static int
118
key_bindings_cmp(struct key_binding *bd1, struct key_binding *bd2)
119
0
{
120
0
  if (bd1->key < bd2->key)
121
0
    return (-1);
122
0
  if (bd1->key > bd2->key)
123
0
    return (1);
124
0
  return (0);
125
0
}
126
127
static void
128
key_bindings_free(struct key_binding *bd)
129
0
{
130
0
  cmd_list_free(bd->cmdlist);
131
0
  free((void *)bd->note);
132
0
  free(bd);
133
0
}
134
135
struct key_table *
136
key_bindings_get_table(const char *name, int create)
137
0
{
138
0
  struct key_table  table_find, *table;
139
140
0
  table_find.name = name;
141
0
  table = RB_FIND(key_tables, &key_tables, &table_find);
142
0
  if (table != NULL || !create)
143
0
    return (table);
144
145
0
  table = xmalloc(sizeof *table);
146
0
  table->name = xstrdup(name);
147
0
  RB_INIT(&table->key_bindings);
148
0
  RB_INIT(&table->default_key_bindings);
149
150
0
  table->references = 1; /* one reference in key_tables */
151
0
  RB_INSERT(key_tables, &key_tables, table);
152
153
0
  return (table);
154
0
}
155
156
struct key_table *
157
key_bindings_first_table(void)
158
0
{
159
0
  return (RB_MIN(key_tables, &key_tables));
160
0
}
161
162
struct key_table *
163
key_bindings_next_table(struct key_table *table)
164
0
{
165
0
  return (RB_NEXT(key_tables, &key_tables, table));
166
0
}
167
168
void
169
key_bindings_unref_table(struct key_table *table)
170
0
{
171
0
  struct key_binding  *bd;
172
0
  struct key_binding  *bd1;
173
174
0
  if (--table->references != 0)
175
0
    return;
176
177
0
  RB_FOREACH_SAFE(bd, key_bindings, &table->key_bindings, bd1) {
178
0
    RB_REMOVE(key_bindings, &table->key_bindings, bd);
179
0
    key_bindings_free(bd);
180
0
  }
181
0
  RB_FOREACH_SAFE(bd, key_bindings, &table->default_key_bindings, bd1) {
182
0
    RB_REMOVE(key_bindings, &table->default_key_bindings, bd);
183
0
    key_bindings_free(bd);
184
0
  }
185
186
0
  free((void *)table->name);
187
0
  free(table);
188
0
}
189
190
struct key_binding *
191
key_bindings_get(struct key_table *table, key_code key)
192
0
{
193
0
  struct key_binding  bd;
194
195
0
  bd.key = key;
196
0
  return (RB_FIND(key_bindings, &table->key_bindings, &bd));
197
0
}
198
199
struct key_binding *
200
key_bindings_get_default(struct key_table *table, key_code key)
201
0
{
202
0
  struct key_binding  bd;
203
204
0
  bd.key = key;
205
0
  return (RB_FIND(key_bindings, &table->default_key_bindings, &bd));
206
0
}
207
208
struct key_binding *
209
key_bindings_first(struct key_table *table)
210
0
{
211
0
  return (RB_MIN(key_bindings, &table->key_bindings));
212
0
}
213
214
struct key_binding *
215
key_bindings_next(__unused struct key_table *table, struct key_binding *bd)
216
0
{
217
0
  return (RB_NEXT(key_bindings, &table->key_bindings, bd));
218
0
}
219
220
void
221
key_bindings_add(const char *name, key_code key, const char *note, int repeat,
222
    struct cmd_list *cmdlist)
223
0
{
224
0
  struct key_table  *table;
225
0
  struct key_binding  *bd;
226
0
  char      *s;
227
228
0
  table = key_bindings_get_table(name, 1);
229
230
0
  bd = key_bindings_get(table, key & ~KEYC_MASK_FLAGS);
231
0
  if (cmdlist == NULL) {
232
0
    if (bd != NULL) {
233
0
      if (note != NULL) {
234
0
        free((void *)bd->note);
235
0
        bd->note = xstrdup(note);
236
0
      }
237
0
      if (repeat)
238
0
        bd->flags |= KEY_BINDING_REPEAT;
239
0
    }
240
0
    return;
241
0
  }
242
0
  if (bd != NULL) {
243
0
    RB_REMOVE(key_bindings, &table->key_bindings, bd);
244
0
    key_bindings_free(bd);
245
0
  }
246
247
0
  bd = xcalloc(1, sizeof *bd);
248
0
  bd->key = (key & ~KEYC_MASK_FLAGS);
249
0
  bd->tablename = table->name;
250
0
  if (note != NULL)
251
0
    bd->note = xstrdup(note);
252
0
  RB_INSERT(key_bindings, &table->key_bindings, bd);
253
254
0
  if (repeat)
255
0
    bd->flags |= KEY_BINDING_REPEAT;
256
0
  bd->cmdlist = cmdlist;
257
258
0
  s = cmd_list_print(bd->cmdlist, 0);
259
0
  log_debug("%s: %#llx %s = %s", __func__, bd->key,
260
0
      key_string_lookup_key(bd->key, 1), s);
261
0
  free(s);
262
0
}
263
264
void
265
key_bindings_remove(const char *name, key_code key)
266
0
{
267
0
  struct key_table  *table;
268
0
  struct key_binding  *bd;
269
270
0
  table = key_bindings_get_table(name, 0);
271
0
  if (table == NULL)
272
0
    return;
273
274
0
  bd = key_bindings_get(table, key & ~KEYC_MASK_FLAGS);
275
0
  if (bd == NULL)
276
0
    return;
277
278
0
  log_debug("%s: %#llx %s", __func__, bd->key,
279
0
      key_string_lookup_key(bd->key, 1));
280
281
0
  RB_REMOVE(key_bindings, &table->key_bindings, bd);
282
0
  key_bindings_free(bd);
283
284
0
  if (RB_EMPTY(&table->key_bindings) &&
285
0
      RB_EMPTY(&table->default_key_bindings)) {
286
0
    RB_REMOVE(key_tables, &key_tables, table);
287
0
    key_bindings_unref_table(table);
288
0
  }
289
0
}
290
291
void
292
key_bindings_reset(const char *name, key_code key)
293
0
{
294
0
  struct key_table  *table;
295
0
  struct key_binding  *bd, *dd;
296
297
0
  table = key_bindings_get_table(name, 0);
298
0
  if (table == NULL)
299
0
    return;
300
301
0
  bd = key_bindings_get(table, key & ~KEYC_MASK_FLAGS);
302
0
  if (bd == NULL)
303
0
    return;
304
305
0
  dd = key_bindings_get_default(table, bd->key);
306
0
  if (dd == NULL) {
307
0
    key_bindings_remove(name, bd->key);
308
0
    return;
309
0
  }
310
311
0
  cmd_list_free(bd->cmdlist);
312
0
  bd->cmdlist = dd->cmdlist;
313
0
  bd->cmdlist->references++;
314
315
0
  free((void *)bd->note);
316
0
  if (dd->note != NULL)
317
0
    bd->note = xstrdup(dd->note);
318
0
  else
319
0
    bd->note = NULL;
320
0
  bd->flags = dd->flags;
321
0
}
322
323
void
324
key_bindings_remove_table(const char *name)
325
0
{
326
0
  struct key_table  *table;
327
0
  struct client   *c;
328
329
0
  table = key_bindings_get_table(name, 0);
330
0
  if (table != NULL) {
331
0
    RB_REMOVE(key_tables, &key_tables, table);
332
0
    TAILQ_FOREACH(c, &clients, entry) {
333
0
      if (c->keytable == table)
334
0
        server_client_set_key_table(c, NULL);
335
0
    }
336
0
    key_bindings_unref_table(table);
337
0
  }
338
0
}
339
340
void
341
key_bindings_reset_table(const char *name)
342
0
{
343
0
  struct key_table  *table;
344
0
  struct key_binding  *bd, *bd1;
345
346
0
  table = key_bindings_get_table(name, 0);
347
0
  if (table == NULL)
348
0
    return;
349
0
  if (RB_EMPTY(&table->default_key_bindings)) {
350
0
    key_bindings_remove_table(name);
351
0
    return;
352
0
  }
353
0
  RB_FOREACH_SAFE(bd, key_bindings, &table->key_bindings, bd1)
354
0
    key_bindings_reset(name, bd->key);
355
0
}
356
357
static enum cmd_retval
358
key_bindings_init_done(__unused struct cmdq_item *item, __unused void *data)
359
0
{
360
0
  struct key_table  *table;
361
0
  struct key_binding  *bd, *new_bd;
362
363
0
  RB_FOREACH(table, key_tables, &key_tables) {
364
0
    RB_FOREACH(bd, key_bindings, &table->key_bindings) {
365
0
      new_bd = xcalloc(1, sizeof *bd);
366
0
      new_bd->key = bd->key;
367
0
      if (bd->note != NULL)
368
0
        new_bd->note = xstrdup(bd->note);
369
0
      new_bd->flags = bd->flags;
370
0
      new_bd->cmdlist = bd->cmdlist;
371
0
      new_bd->cmdlist->references++;
372
0
      RB_INSERT(key_bindings, &table->default_key_bindings,
373
0
          new_bd);
374
0
    }
375
0
  }
376
0
  return (CMD_RETURN_NORMAL);
377
0
}
378
379
void
380
key_bindings_init(void)
381
0
{
382
0
  static const char *const defaults[] = {
383
    /* Prefix keys. */
384
0
    "bind -N 'Send the prefix key' C-b { send-prefix }",
385
0
    "bind -N 'Rotate through the panes' C-o { rotate-window }",
386
0
    "bind -N 'Suspend the current client' C-z { suspend-client }",
387
0
    "bind -N 'Select next layout' Space { next-layout }",
388
0
    "bind -N 'Break pane to a new window' ! { break-pane }",
389
0
    "bind -N 'Split window vertically' '\"' { split-window }",
390
0
    "bind -N 'List all paste buffers' '#' { list-buffers }",
391
0
    "bind -N 'Rename current session' '$' { command-prompt -I'#S' { rename-session -- '%%' } }",
392
0
    "bind -N 'Split window horizontally' % { split-window -h }",
393
0
    "bind -N 'Kill current window' & { confirm-before -p\"kill-window #W? (y/n)\" kill-window }",
394
0
    "bind -N 'Prompt for window index to select' \"'\" { command-prompt -pindex { select-window -t ':%%' } }",
395
0
    "bind -N 'New floating pane' * { new-pane }",
396
0
    "bind -N 'Toggle pane between floating and tiled' @ { if -F '#{pane_floating_flag}' { join-pane } { break-pane -W } }",
397
0
    "bind -N 'Switch to previous client' ( { switch-client -p }",
398
0
    "bind -N 'Switch to next client' ) { switch-client -n }",
399
0
    "bind -N 'Rename current window' , { command-prompt -I'#W' { rename-window -- '%%' } }",
400
0
    "bind -N 'Delete the most recent paste buffer' - { delete-buffer }",
401
0
    "bind -N 'Move the current window' . { command-prompt { move-window -t '%%' } }",
402
0
    "bind -N 'Describe key binding' '/' { command-prompt -kpkey  { list-keys -1N '%%' } }",
403
0
    "bind -N 'Select window 0' 0 { select-window -t:=0 }",
404
0
    "bind -N 'Select window 1' 1 { select-window -t:=1 }",
405
0
    "bind -N 'Select window 2' 2 { select-window -t:=2 }",
406
0
    "bind -N 'Select window 3' 3 { select-window -t:=3 }",
407
0
    "bind -N 'Select window 4' 4 { select-window -t:=4 }",
408
0
    "bind -N 'Select window 5' 5 { select-window -t:=5 }",
409
0
    "bind -N 'Select window 6' 6 { select-window -t:=6 }",
410
0
    "bind -N 'Select window 7' 7 { select-window -t:=7 }",
411
0
    "bind -N 'Select window 8' 8 { select-window -t:=8 }",
412
0
    "bind -N 'Select window 9' 9 { select-window -t:=9 }",
413
0
    "bind -N 'Prompt for a command' : { command-prompt }",
414
0
    "bind -N 'Move to the previously active pane' \\; { last-pane }",
415
0
    "bind -N 'Choose a paste buffer from a list' = { choose-buffer -Z }",
416
0
    "bind -N 'List key bindings' ? { list-keys -N }",
417
0
    "bind -N 'Choose and detach a client from a list' D { choose-client -Z }",
418
0
    "bind -N 'Spread panes out evenly' E { select-layout -E }",
419
0
    "bind -N 'Switch to the last client' L { switch-client -l }",
420
0
    "bind -N 'Clear the marked pane' M { select-pane -M }",
421
0
    "bind -N 'Enter copy mode' [ { copy-mode }",
422
0
    "bind -N 'Paste the most recent paste buffer' ] { paste-buffer -p }",
423
0
    "bind -N 'Create a new window' c { new-window }",
424
0
    "bind -N 'Detach the current client' d { detach-client }",
425
0
    "bind -N 'Search for a pane' f { command-prompt { find-window -Z -- '%%' } }",
426
0
    "bind -N 'Display window information' i { display-message }",
427
0
    "bind -N 'Select the previously current window' l { last-window }",
428
0
    "bind -N 'Toggle the marked pane' m { select-pane -m }",
429
0
    "bind -N 'Select the next window' n { next-window }",
430
0
    "bind -N 'Select the next pane' o { select-pane -t:.+ }",
431
0
    "bind -N 'Customize options' C { customize-mode -Z }",
432
0
    "bind -N 'Select the previous window' p { previous-window }",
433
0
    "bind -N 'Display pane numbers' q { display-panes }",
434
0
    "bind -N 'Redraw the current client' r { refresh-client }",
435
0
    "bind -N 'Choose a session from a list' s { choose-tree -Zs }",
436
0
    "bind -N 'Show a clock' t { clock-mode }",
437
0
    "bind -N 'Switch to a window' Tab { new-pane -E -x75% -y30% -X0 -Y0; move-pane -P bottom-centre; switch-mode -wk }",
438
0
    "bind -N 'Switch to a session' BTab { new-pane -E -x75% -y30% -X0 -Y0; move-pane -P bottom-centre; switch-mode -sk }",
439
0
    "bind -N 'Choose a window from a list' w { choose-tree -Zw }",
440
0
    "bind -N 'Kill the active pane' x { confirm-before -p\"kill-pane #P? (y/n)\" kill-pane }",
441
0
    "bind -N 'Zoom the active pane' z { resize-pane -Z }",
442
0
    "bind -N 'Swap the active pane with the pane above' '{' { swap-pane -U }",
443
0
    "bind -N 'Swap the active pane with the pane below' '}' { swap-pane -D }",
444
0
    "bind -N 'Show messages' '~' { show-messages }",
445
0
    "bind -N 'Enter copy mode and scroll up' PPage { copy-mode -u }",
446
0
    "bind -N 'Select the pane above the active pane' -r Up { select-pane -U }",
447
0
    "bind -N 'Select the pane below the active pane' -r Down { select-pane -D }",
448
0
    "bind -N 'Select the pane to the left of the active pane' -r Left { select-pane -L }",
449
0
    "bind -N 'Select the pane to the right of the active pane' -r Right { select-pane -R }",
450
0
    "bind -N 'Set the even-horizontal layout' M-1 { select-layout even-horizontal }",
451
0
    "bind -N 'Set the even-vertical layout' M-2 { select-layout even-vertical }",
452
0
    "bind -N 'Set the main-horizontal layout' M-3 { select-layout main-horizontal }",
453
0
    "bind -N 'Set the main-vertical layout' M-4 { select-layout main-vertical }",
454
0
    "bind -N 'Select the tiled layout' M-5 { select-layout tiled }",
455
0
    "bind -N 'Set the main-horizontal-mirrored layout' M-6 { select-layout main-horizontal-mirrored }",
456
0
    "bind -N 'Set the main-vertical-mirrored layout' M-7 { select-layout main-vertical-mirrored }",
457
0
    "bind -N 'Select the next window with an alert' M-n { next-window -a }",
458
0
    "bind -N 'Rotate through the panes in reverse' M-o { rotate-window -D }",
459
0
    "bind -N 'Select the previous window with an alert' M-p { previous-window -a }",
460
0
    "bind -N 'Move the visible part of the window up' -r S-Up { refresh-client -U 10 }",
461
0
    "bind -N 'Move the visible part of the window down' -r S-Down { refresh-client -D 10 }",
462
0
    "bind -N 'Move the visible part of the window left' -r S-Left { refresh-client -L 10 }",
463
0
    "bind -N 'Move the visible part of the window right' -r S-Right { refresh-client -R 10 }",
464
0
    "bind -N 'Reset so the visible part of the window follows the cursor' -r DC { refresh-client -c }",
465
0
    "bind -N 'Resize the pane up by 5' -r M-Up if -F '#{?floating_pane_flag}' { resizep -D-5 } { resize-pane -U 5 }",
466
0
    "bind -N 'Resize the pane down by 5' -r M-Down { resize-pane -D 5 }",
467
0
    "bind -N 'Resize the pane left by 5' -r M-Left if -F '#{?floating_pane_flag}' { resizep -R-5 } { resize-pane -L 5 }",
468
0
    "bind -N 'Resize the pane right by 5' -r M-Right resize-pane -R 5",
469
0
    "bind -N 'Resize the pane up' -r C-Up if -F '#{?floating_pane_flag}' { resizep -D-1 } { resize-pane -U }",
470
0
    "bind -N 'Resize the pane down' -r C-Down { resize-pane -D }",
471
0
    "bind -N 'Resize the pane left' -r C-Left if -F '#{?floating_pane_flag}' { resizep -R-1 } { resize-pane -L }",
472
0
    "bind -N 'Resize the pane right' -r C-Right { resize-pane -R }",
473
474
    /* Floating pane movement. */
475
0
    "bind -N 'Move a floating pane' g { switch-client -Tmove }",
476
0
    "bind -Tmove -N 'Move pane to top-left corner' 1 { move-pane -P top-left }",
477
0
    "bind -Tmove -N 'Move pane to top-right corner' 2 { move-pane -P top-right }",
478
0
    "bind -Tmove -N 'Move pane to bottom-left corner' 3 { move-pane -P bottom-left }",
479
0
    "bind -Tmove -N 'Move pane to bottom-right corner' 4 { move-pane -P bottom-right }",
480
0
    "bind -Tmove -N 'Move pane to top-left corner and resize' M-1 { resize-pane -x50% -y50%; move-pane -P top-left }",
481
0
    "bind -Tmove -N 'Move pane to top-right corner and resize' M-2 { resize-pane -x50% -y50%; move-pane -P top-right }",
482
0
    "bind -Tmove -N 'Move pane to bottom-left corner and resize' M-3 { resize-pane -x50% -y50%; move-pane -P bottom-left }",
483
0
    "bind -Tmove -N 'Move pane to bottom-right corner and resize' M-4 { resize-pane -x50% -y50%; move-pane -P bottom-right }",
484
0
    "bind -Tmove -N 'Move pane to top' 'Up' { move-pane -P top-centre }",
485
0
    "bind -Tmove -N 'Move pane to bottom' 'Down' { move-pane -P bottom-centre  }",
486
0
    "bind -Tmove -N 'Move pane to left' 'Left' { move-pane -P centre-left }",
487
0
    "bind -Tmove -N 'Move pane to right' 'Right' { move-pane -P centre-right }",
488
0
    "bind -Tmove -N 'Move pane to top and resize' 'M-Up' { resizep -x100% -y50%; move-pane -P top-centre }",
489
0
    "bind -Tmove -N 'Move pane to bottom and resize' 'M-Down' { resizep -x100% -y50%; move-pane -P bottom-centre  }",
490
0
    "bind -Tmove -N 'Move pane to left and resize' 'M-Left' { resizep -x50% -y100%; move-pane -P centre-left }",
491
0
    "bind -Tmove -N 'Move pane to right and resize' 'M-Right' { resizep -x50% -y100%; move-pane -P centre-right }",
492
0
    "bind -Tmove -N 'Move pane to fill the window' 0 { resize-pane -x100% -y100%; move-pane -P top-left }",
493
0
    "bind -Tmove -N 'Display move menu' , { if -F '#{pane_floating_flag}' { display-menu -xP -yP -T '#[align=centre]Move' " DEFAULT_MOVE_MENU " } }",
494
0
    "bind -Tmove -N 'Display move and resize menu' . { if -F '#{pane_floating_flag}' { display-menu -xP -yP -T '#[align=centre]Move & Resize' " DEFAULT_MOVE_RESIZE_MENU " } }",
495
496
    /* Menu keys */
497
0
    "bind -N 'Display window menu' < { display-menu -xW -yW -T '#[align=centre]#{window_index}:#{window_name}' " DEFAULT_WINDOW_MENU " }",
498
0
    "bind -N 'Display pane menu' > { display-menu -xP -yP -T '#[align=centre]#{pane_index} (#{pane_id})' " DEFAULT_PANE_MENU " }",
499
500
    /* Mouse button 1 down on pane. */
501
0
    "bind -n MouseDown1Pane { select-pane -t=; send -M }",
502
503
    /* Mouse button 1 drag on pane. */
504
0
    "bind -n MouseDrag1Pane { if -F '#{||:#{pane_in_mode},#{mouse_any_flag}}' { send -M } { copy-mode -M } }",
505
0
    "bind -n C-MouseDrag1Pane { new-pane -M }",
506
0
    "bind -n C-MouseDrag1Empty { new-pane -M }",
507
0
    "bind -n M-MouseDrag1Pane { move-pane -M }",
508
509
    /* Mouse wheel up on pane. */
510
0
    "bind -n WheelUpPane { if -F '#{||:#{alternate_on},#{pane_in_mode},#{mouse_any_flag}}' { send -M } { copy-mode -e } }",
511
512
    /* Mouse button 2 down on pane. */
513
0
    "bind -n MouseDown2Pane { select-pane -t=; if -F '#{||:#{pane_in_mode},#{mouse_any_flag}}' { send -M } { paste -p } }",
514
515
    /* Mouse button 1 double click on pane. */
516
0
    "bind -n DoubleClick1Pane { select-pane -t=; if -F '#{||:#{pane_in_mode},#{mouse_any_flag}}' { send -M } { copy-mode -H; send -X select-word; run -d0.3; send -X copy-pipe-and-cancel } }",
517
518
    /* Mouse button 1 triple click on pane. */
519
0
    "bind -n TripleClick1Pane { select-pane -t=; if -F '#{||:#{pane_in_mode},#{mouse_any_flag}}' { send -M } { copy-mode -H; send -X select-line; run -d0.3; send -X copy-pipe-and-cancel } }",
520
521
    /* Mouse button 1 on border. */
522
0
    "bind -n MouseDown1Border { select-pane -M }",
523
524
    /* Mouse button 1 drag on border. */
525
0
    "bind -n MouseDrag1Border { resize-pane -M }",
526
0
    "bind -n M-MouseDrag1Border { move-pane -M }",
527
528
    /* Mouse button 1 down on status line. */
529
0
    "bind -n MouseDown1Status { switch-client -t= }",
530
0
    "bind -n C-MouseDown1Status { swap-window -t@ }",
531
532
    /* Mouse button 1 down on default pane-border-format */
533
0
    "bind -n MouseDown1Control9 { display-menu -t= -xM -yM -O -T 'Kill pane #{pane_index}?' 'Yes' 'y' { kill-pane -t= } 'No' 'n' {}}",
534
0
    "bind -n MouseDown1Control8 { resize-pane -Z }",
535
0
    "bind -n MouseDown1Control7 { if -Ft= '#{pane_floating_flag}' { join-pane } { break-pane -W } }",
536
537
    /* Mouse wheel down on status line. */
538
0
    "bind -n WheelDownStatus { next-window }",
539
540
    /* Mouse wheel up on status line. */
541
0
    "bind -n WheelUpStatus { previous-window }",
542
543
    /* Mouse button 3 down on status left. */
544
0
    "bind -n MouseDown3StatusLeft { run -C \"display-menu -t= -xM -yW -T '#[align=centre]#{session_name}' " DEFAULT_SESSION_MENU "\" }",
545
0
    "bind -n M-MouseDown3StatusLeft { run -C \"display-menu -t= -xM -yW -T '#[align=centre]#{session_name}' " DEFAULT_SESSION_MENU "\" }",
546
547
    /* Mouse button 3 down on status line. */
548
0
    "bind -n MouseDown3Status { display-menu -t= -xW -yW -T '#[align=centre]#{window_index}:#{window_name}' " DEFAULT_WINDOW_MENU "}",
549
0
    "bind -n M-MouseDown3Status { display-menu -t= -xW -yW -T '#[align=centre]#{window_index}:#{window_name}' " DEFAULT_WINDOW_MENU "}",
550
551
    /* Mouse button 3 down on pane. */
552
0
    "bind -n MouseDown3Pane { if -Ft= '#{||:#{mouse_any_flag},#{&&:#{pane_in_mode},#{?#{m/r:(copy|view)-mode,#{pane_mode}},0,1}}}' { select-pane -t=; send -M } { display-menu -t= -xM -yM -T '#[align=centre]#{pane_index} (#{pane_id})' " DEFAULT_PANE_MENU " } }",
553
0
    "bind -n M-MouseDown3Pane { display-menu -t= -xM -yM -T '#[align=centre]#{pane_index} (#{pane_id})' " DEFAULT_PANE_MENU " }",
554
555
    /* Mouse on scrollbar. */
556
0
    "bind -n MouseDown1ScrollbarUp { if -Ft= '#{pane_in_mode}' { send -X page-up } {copy-mode -u } }",
557
0
    "bind -n MouseDown1ScrollbarDown { if -Ft= '#{pane_in_mode}' { send -X page-down } {copy-mode -d } }",
558
0
    "bind -n MouseDrag1ScrollbarSlider { if -Ft= '#{pane_in_mode}' { send -X scroll-to-mouse } { copy-mode -S } }",
559
560
    /* Copy mode (emacs) keys. */
561
0
    "bind -Tcopy-mode C-Space { send -X begin-selection }",
562
0
    "bind -Tcopy-mode C-a { send -X start-of-line }",
563
0
    "bind -Tcopy-mode C-c { send -X cancel }",
564
0
    "bind -Tcopy-mode C-e { send -X end-of-line }",
565
0
    "bind -Tcopy-mode C-f { send -X cursor-right }",
566
0
    "bind -Tcopy-mode C-b { send -X cursor-left }",
567
0
    "bind -Tcopy-mode C-g { send -X clear-selection }",
568
0
    "bind -Tcopy-mode C-k { send -X copy-pipe-end-of-line-and-cancel }",
569
0
    "bind -Tcopy-mode C-l { send -X recentre-top-bottom }",
570
0
    "bind -Tcopy-mode M-l { send -X cursor-centre-horizontal }",
571
0
    "bind -Tcopy-mode C-n { send -X cursor-down }",
572
0
    "bind -Tcopy-mode C-p { send -X cursor-up }",
573
0
    "bind -Tcopy-mode C-r { command-prompt -P -T search -ip'(search up)' -I'#{pane_search_string}' { send -X search-backward-incremental -- '%%' } }",
574
0
    "bind -Tcopy-mode C-s { command-prompt -P -T search -ip'(search down)' -I'#{pane_search_string}' { send -X search-forward-incremental -- '%%' } }",
575
0
    "bind -Tcopy-mode C-v { send -X page-down }",
576
0
    "bind -Tcopy-mode C-w { send -X copy-pipe-and-cancel }",
577
0
    "bind -Tcopy-mode Escape { send -X cancel }",
578
0
    "bind -Tcopy-mode C-[ { send -X cancel }",
579
0
    "bind -Tcopy-mode Space { send -X page-down }",
580
0
    "bind -Tcopy-mode , { send -X jump-reverse }",
581
0
    "bind -Tcopy-mode \\; { send -X jump-again }",
582
0
    "bind -Tcopy-mode F { command-prompt -P -1p'(jump backward)' { send -X jump-backward -- '%%' } }",
583
0
    "bind -Tcopy-mode L { send -X line-numbers-toggle }",
584
0
    "bind -Tcopy-mode N { send -X search-reverse }",
585
0
    "bind -Tcopy-mode P { send -X toggle-position }",
586
0
    "bind -Tcopy-mode R { send -X rectangle-toggle }",
587
0
    "bind -Tcopy-mode T { command-prompt -P -1p'(jump to backward)' { send -X jump-to-backward -- '%%' } }",
588
0
    "bind -Tcopy-mode X { send -X set-mark }",
589
0
    "bind -Tcopy-mode f { command-prompt -P -1p'(jump forward)' { send -X jump-forward -- '%%' } }",
590
0
    "bind -Tcopy-mode g { command-prompt -P -p'(goto line)' { send -X goto-line -- '%%' } }",
591
0
    "bind -Tcopy-mode n { send -X search-again }",
592
0
    "bind -Tcopy-mode q { send -X cancel }",
593
0
    "bind -Tcopy-mode r { send -X refresh-toggle }",
594
0
    "bind -Tcopy-mode t { command-prompt -P -1p'(jump to forward)' { send -X jump-to-forward -- '%%' } }",
595
0
    "bind -Tcopy-mode Home { send -X start-of-line }",
596
0
    "bind -Tcopy-mode End { send -X end-of-line }",
597
0
    "bind -Tcopy-mode MouseDown1Pane select-pane",
598
0
    "bind -Tcopy-mode MouseDrag1Pane { select-pane; send -X begin-selection }",
599
0
    "bind -Tcopy-mode MouseDragEnd1Pane { send -X copy-pipe-and-cancel }",
600
0
    "bind -Tcopy-mode WheelUpPane { select-pane; send -N5 -X scroll-up }",
601
0
    "bind -Tcopy-mode WheelDownPane { select-pane; send -N5 -X scroll-down }",
602
0
    "bind -Tcopy-mode DoubleClick1Pane { select-pane; send -X select-word; run -d0.3; send -X copy-pipe-and-cancel }",
603
0
    "bind -Tcopy-mode TripleClick1Pane { select-pane; send -X select-line; run -d0.3; send -X copy-pipe-and-cancel }",
604
0
    "bind -Tcopy-mode NPage { send -X page-down }",
605
0
    "bind -Tcopy-mode PPage { send -X page-up }",
606
0
    "bind -Tcopy-mode Up { send -X cursor-up }",
607
0
    "bind -Tcopy-mode Down { send -X cursor-down }",
608
0
    "bind -Tcopy-mode Left { send -X cursor-left }",
609
0
    "bind -Tcopy-mode Right { send -X cursor-right }",
610
0
    "bind -Tcopy-mode M-1 { command-prompt -P -Np'(repeat)' -I1 { send -N '%%' } }",
611
0
    "bind -Tcopy-mode M-2 { command-prompt -P -Np'(repeat)' -I2 { send -N '%%' } }",
612
0
    "bind -Tcopy-mode M-3 { command-prompt -P -Np'(repeat)' -I3 { send -N '%%' } }",
613
0
    "bind -Tcopy-mode M-4 { command-prompt -P -Np'(repeat)' -I4 { send -N '%%' } }",
614
0
    "bind -Tcopy-mode M-5 { command-prompt -P -Np'(repeat)' -I5 { send -N '%%' } }",
615
0
    "bind -Tcopy-mode M-6 { command-prompt -P -Np'(repeat)' -I6 { send -N '%%' } }",
616
0
    "bind -Tcopy-mode M-7 { command-prompt -P -Np'(repeat)' -I7 { send -N '%%' } }",
617
0
    "bind -Tcopy-mode M-8 { command-prompt -P -Np'(repeat)' -I8 { send -N '%%' } }",
618
0
    "bind -Tcopy-mode M-9 { command-prompt -P -Np'(repeat)' -I9 { send -N '%%' } }",
619
0
    "bind -Tcopy-mode M-< { send -X history-top }",
620
0
    "bind -Tcopy-mode M-> { send -X history-bottom }",
621
0
    "bind -Tcopy-mode M-R { send -X top-line }",
622
0
    "bind -Tcopy-mode M-b { send -X previous-word }",
623
0
    "bind -Tcopy-mode C-M-b { send -X previous-matching-bracket }",
624
0
    "bind -Tcopy-mode M-f { send -X next-word-end }",
625
0
    "bind -Tcopy-mode C-M-f { send -X next-matching-bracket }",
626
0
    "bind -Tcopy-mode M-m { send -X back-to-indentation }",
627
0
    "bind -Tcopy-mode M-r { send -X middle-line }",
628
0
    "bind -Tcopy-mode M-v { send -X page-up }",
629
0
    "bind -Tcopy-mode M-w { send -X copy-pipe-and-cancel }",
630
0
    "bind -Tcopy-mode M-x { send -X jump-to-mark }",
631
0
    "bind -Tcopy-mode 'M-{' { send -X previous-paragraph }",
632
0
    "bind -Tcopy-mode 'M-}' { send -X next-paragraph }",
633
0
    "bind -Tcopy-mode M-Up { send -X halfpage-up }",
634
0
    "bind -Tcopy-mode M-Down { send -X halfpage-down }",
635
0
    "bind -Tcopy-mode C-Up { send -X scroll-up }",
636
0
    "bind -Tcopy-mode C-Down { send -X scroll-down }",
637
0
    "bind -Tcopy-mode M-C-Up { send -X previous-prompt }",
638
0
    "bind -Tcopy-mode M-C-Down { send -X next-prompt }",
639
640
    /* Copy mode (vi) keys. */
641
0
    "bind -Tcopy-mode-vi '#' { send -FX search-backward -- '#{copy_cursor_word}' }",
642
0
    "bind -Tcopy-mode-vi * { send -FX search-forward -- '#{copy_cursor_word}' }",
643
0
    "bind -Tcopy-mode-vi C-c { send -X cancel }",
644
0
    "bind -Tcopy-mode-vi C-d { send -X halfpage-down }",
645
0
    "bind -Tcopy-mode-vi C-e { send -X scroll-down }",
646
0
    "bind -Tcopy-mode-vi C-b { send -X page-up }",
647
0
    "bind -Tcopy-mode-vi C-f { send -X page-down }",
648
0
    "bind -Tcopy-mode-vi C-h { send -X cursor-left }",
649
0
    "bind -Tcopy-mode-vi C-j { send -X copy-pipe-and-cancel }",
650
0
    "bind -Tcopy-mode-vi Enter { send -X copy-pipe-and-cancel }",
651
0
    "bind -Tcopy-mode-vi C-u { send -X halfpage-up }",
652
0
    "bind -Tcopy-mode-vi C-v { send -X rectangle-toggle }",
653
0
    "bind -Tcopy-mode-vi C-y { send -X scroll-up }",
654
0
    "bind -Tcopy-mode-vi Escape { send -X clear-selection }",
655
0
    "bind -Tcopy-mode-vi C-[ { send -X clear-selection }",
656
0
    "bind -Tcopy-mode-vi Space { send -X begin-selection }",
657
0
    "bind -Tcopy-mode-vi '$' { send -X end-of-line }",
658
0
    "bind -Tcopy-mode-vi , { send -X jump-reverse }",
659
0
    "bind -Tcopy-mode-vi / { command-prompt -P -T search -p'(search down)' { send -X search-forward -- '%%' } }",
660
0
    "bind -Tcopy-mode-vi 0 { send -X start-of-line }",
661
0
    "bind -Tcopy-mode-vi 1 { command-prompt -P -Np'(repeat)' -I1 { send -N '%%' } }",
662
0
    "bind -Tcopy-mode-vi 2 { command-prompt -P -Np'(repeat)' -I2 { send -N '%%' } }",
663
0
    "bind -Tcopy-mode-vi 3 { command-prompt -P -Np'(repeat)' -I3 { send -N '%%' } }",
664
0
    "bind -Tcopy-mode-vi 4 { command-prompt -P -Np'(repeat)' -I4 { send -N '%%' } }",
665
0
    "bind -Tcopy-mode-vi 5 { command-prompt -P -Np'(repeat)' -I5 { send -N '%%' } }",
666
0
    "bind -Tcopy-mode-vi 6 { command-prompt -P -Np'(repeat)' -I6 { send -N '%%' } }",
667
0
    "bind -Tcopy-mode-vi 7 { command-prompt -P -Np'(repeat)' -I7 { send -N '%%' } }",
668
0
    "bind -Tcopy-mode-vi 8 { command-prompt -P -Np'(repeat)' -I8 { send -N '%%' } }",
669
0
    "bind -Tcopy-mode-vi 9 { command-prompt -P -Np'(repeat)' -I9 { send -N '%%' } }",
670
0
    "bind -Tcopy-mode-vi : { command-prompt -P -p'(goto line)' { send -X goto-line -- '%%' } }",
671
0
    "bind -Tcopy-mode-vi \\; { send -X jump-again }",
672
0
    "bind -Tcopy-mode-vi ? { command-prompt -P -T search -p'(search up)' { send -X search-backward -- '%%' } }",
673
0
    "bind -Tcopy-mode-vi A { send -X append-selection-and-cancel }",
674
0
    "bind -Tcopy-mode-vi B { send -X previous-space }",
675
0
    "bind -Tcopy-mode-vi D { send -X copy-pipe-end-of-line-and-cancel }",
676
0
    "bind -Tcopy-mode-vi E { send -X next-space-end }",
677
0
    "bind -Tcopy-mode-vi F { command-prompt -P -1p'(jump backward)' { send -X jump-backward -- '%%' } }",
678
0
    "bind -Tcopy-mode-vi G { send -X history-bottom }",
679
0
    "bind -Tcopy-mode-vi H { send -X top-line }",
680
0
    "bind -Tcopy-mode-vi J { send -X scroll-down }",
681
0
    "bind -Tcopy-mode-vi K { send -X scroll-up }",
682
0
    "bind -Tcopy-mode-vi L { send -X bottom-line }",
683
0
    "bind -Tcopy-mode-vi M { send -X middle-line }",
684
0
    "bind -Tcopy-mode-vi N { send -X search-reverse }",
685
0
    "bind -Tcopy-mode-vi P { send -X toggle-position }",
686
0
    "bind -Tcopy-mode-vi T { command-prompt -P -1p'(jump to backward)' { send -X jump-to-backward -- '%%' } }",
687
0
    "bind -Tcopy-mode-vi V { send -X select-line }",
688
0
    "bind -Tcopy-mode-vi W { send -X next-space }",
689
0
    "bind -Tcopy-mode-vi X { send -X set-mark }",
690
0
    "bind -Tcopy-mode-vi ^ { send -X back-to-indentation }",
691
0
    "bind -Tcopy-mode-vi b { send -X previous-word }",
692
0
    "bind -Tcopy-mode-vi e { send -X next-word-end }",
693
0
    "bind -Tcopy-mode-vi f { command-prompt -P -1p'(jump forward)' { send -X jump-forward -- '%%' } }",
694
0
    "bind -Tcopy-mode-vi g { send -X history-top }",
695
0
    "bind -Tcopy-mode-vi h { send -X cursor-left }",
696
0
    "bind -Tcopy-mode-vi j { send -X cursor-down }",
697
0
    "bind -Tcopy-mode-vi k { send -X cursor-up }",
698
0
    "bind -Tcopy-mode-vi z { send -X scroll-middle }",
699
0
    "bind -Tcopy-mode-vi l { send -X cursor-right }",
700
0
    "bind -Tcopy-mode-vi n { send -X search-again }",
701
0
    "bind -Tcopy-mode-vi o { send -X other-end }",
702
0
    "bind -Tcopy-mode-vi q { send -X cancel }",
703
0
    "bind -Tcopy-mode-vi r { send -X refresh-toggle }",
704
0
    "bind -Tcopy-mode-vi t { command-prompt -P -1p'(jump to forward)' { send -X jump-to-forward -- '%%' } }",
705
0
    "bind -Tcopy-mode-vi v { send -X rectangle-toggle }",
706
0
    "bind -Tcopy-mode-vi w { send -X next-word }",
707
0
    "bind -Tcopy-mode-vi '{' { send -X previous-paragraph }",
708
0
    "bind -Tcopy-mode-vi '}' { send -X next-paragraph }",
709
0
    "bind -Tcopy-mode-vi % { send -X next-matching-bracket }",
710
0
    "bind -Tcopy-mode-vi Home { send -X start-of-line }",
711
0
    "bind -Tcopy-mode-vi End { send -X end-of-line }",
712
0
    "bind -Tcopy-mode-vi MouseDown1Pane { select-pane }",
713
0
    "bind -Tcopy-mode-vi MouseDrag1Pane { select-pane; send -X begin-selection }",
714
0
    "bind -Tcopy-mode-vi MouseDragEnd1Pane { send -X copy-pipe-and-cancel }",
715
0
    "bind -Tcopy-mode-vi WheelUpPane { select-pane; send -N5 -X scroll-up }",
716
0
    "bind -Tcopy-mode-vi WheelDownPane { select-pane; send -N5 -X scroll-down }",
717
0
    "bind -Tcopy-mode-vi DoubleClick1Pane { select-pane; send -X select-word; run -d0.3; send -X copy-pipe-and-cancel }",
718
0
    "bind -Tcopy-mode-vi TripleClick1Pane { select-pane; send -X select-line; run -d0.3; send -X copy-pipe-and-cancel }",
719
0
    "bind -Tcopy-mode-vi BSpace { send -X cursor-left }",
720
0
    "bind -Tcopy-mode-vi NPage { send -X page-down }",
721
0
    "bind -Tcopy-mode-vi PPage { send -X page-up }",
722
0
    "bind -Tcopy-mode-vi Up { send -X cursor-up }",
723
0
    "bind -Tcopy-mode-vi Down { send -X cursor-down }",
724
0
    "bind -Tcopy-mode-vi Left { send -X cursor-left }",
725
0
    "bind -Tcopy-mode-vi Right { send -X cursor-right }",
726
0
    "bind -Tcopy-mode-vi M-x { send -X jump-to-mark }",
727
0
    "bind -Tcopy-mode-vi C-Up { send -X scroll-up }",
728
0
    "bind -Tcopy-mode-vi C-Down { send -X scroll-down }",
729
0
  };
730
0
  u_int      i;
731
0
  struct cmd_parse_result *pr;
732
733
0
  for (i = 0; i < nitems(defaults); i++) {
734
0
    pr = cmd_parse_from_string(defaults[i], NULL);
735
0
    if (pr->status != CMD_PARSE_SUCCESS) {
736
0
      log_debug("%s", pr->error);
737
0
      fatalx("bad default key: %s", defaults[i]);
738
0
    }
739
0
    cmdq_append(NULL, cmdq_get_command(pr->cmdlist, NULL));
740
0
    cmd_list_free(pr->cmdlist);
741
0
  }
742
0
  cmdq_append(NULL, cmdq_get_callback(key_bindings_init_done, NULL));
743
0
}
744
745
static enum cmd_retval
746
key_bindings_read_only(struct cmdq_item *item, __unused void *data)
747
0
{
748
0
  cmdq_error(item, "client is read-only");
749
0
  return (CMD_RETURN_ERROR);
750
0
}
751
752
struct cmdq_item *
753
key_bindings_dispatch(struct key_binding *bd, struct cmdq_item *item,
754
    struct client *c, struct key_event *event, struct cmd_find_state *fs)
755
0
{
756
0
  struct cmdq_item  *new_item;
757
0
  struct cmdq_state *new_state;
758
0
  int      readonly, flags = 0;
759
760
0
  if (c == NULL || (~c->flags & CLIENT_READONLY))
761
0
    readonly = 1;
762
0
  else
763
0
    readonly = cmd_list_all_have(bd->cmdlist, CMD_READONLY);
764
765
0
  if (!readonly)
766
0
    new_item = cmdq_get_callback(key_bindings_read_only, NULL);
767
0
  else {
768
0
    if (bd->flags & KEY_BINDING_REPEAT)
769
0
      flags |= CMDQ_STATE_REPEAT;
770
0
    new_state = cmdq_new_state(fs, event, flags);
771
0
    new_item = cmdq_get_command(bd->cmdlist, new_state);
772
0
    cmdq_free_state(new_state);
773
0
  }
774
0
  if (item != NULL)
775
0
    new_item = cmdq_insert_after(item, new_item);
776
0
  else
777
0
    new_item = cmdq_append(c, new_item);
778
0
  return (new_item);
779
0
}
780
781
int
782
key_bindings_has_repeat(struct key_binding **l, u_int n)
783
0
{
784
0
  u_int i;
785
786
0
  for (i = 0; i < n; i++) {
787
0
    if (l[i]->flags & KEY_BINDING_REPEAT)
788
0
      return (1);
789
0
  }
790
0
  return (0);
791
0
}