Coverage Report

Created: 2026-07-30 07:06

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