mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 00:56:10 +00:00 
			
		
		
		
	Add support for adding a note to a key binding (with bind-key -N) and
use this to add descriptions to the default key bindings. A new -N flag to list-keys shows key bindings with notes rather than the default bind-key command used to create them. Change the default ? binding to use this to show a readable summary of keys. Also extend command-prompt to return the name of the key pressed and add a default binding (/) to show the note for the next key pressed Suggested by Alex Tremblay in GitHub issue 2000.
This commit is contained in:
		
							
								
								
									
										168
									
								
								key-bindings.c
									
									
									
									
									
								
							
							
						
						
									
										168
									
								
								key-bindings.c
									
									
									
									
									
								
							@@ -90,6 +90,7 @@ key_bindings_free(struct key_table *table, struct key_binding *bd)
 | 
			
		||||
{
 | 
			
		||||
	RB_REMOVE(key_bindings, &table->key_bindings, bd);
 | 
			
		||||
	cmd_list_free(bd->cmdlist);
 | 
			
		||||
	free((void *)bd->note);
 | 
			
		||||
	free(bd);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -163,7 +164,7 @@ key_bindings_next(__unused struct key_table *table, struct key_binding *bd)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
key_bindings_add(const char *name, key_code key, int repeat,
 | 
			
		||||
key_bindings_add(const char *name, key_code key, const char *note, int repeat,
 | 
			
		||||
    struct cmd_list *cmdlist)
 | 
			
		||||
{
 | 
			
		||||
	struct key_table	*table;
 | 
			
		||||
@@ -177,6 +178,8 @@ key_bindings_add(const char *name, key_code key, int repeat,
 | 
			
		||||
 | 
			
		||||
	bd = xcalloc(1, sizeof *bd);
 | 
			
		||||
	bd->key = key;
 | 
			
		||||
	if (note != NULL)
 | 
			
		||||
		bd->note = xstrdup(note);
 | 
			
		||||
	RB_INSERT(key_bindings, &table->key_bindings, bd);
 | 
			
		||||
 | 
			
		||||
	if (repeat)
 | 
			
		||||
@@ -226,87 +229,88 @@ void
 | 
			
		||||
key_bindings_init(void)
 | 
			
		||||
{
 | 
			
		||||
	static const char *defaults[] = {
 | 
			
		||||
		"bind C-b send-prefix",
 | 
			
		||||
		"bind C-o rotate-window",
 | 
			
		||||
		"bind C-z suspend-client",
 | 
			
		||||
		"bind Space next-layout",
 | 
			
		||||
		"bind ! break-pane",
 | 
			
		||||
		"bind '\"' split-window",
 | 
			
		||||
		"bind '#' list-buffers",
 | 
			
		||||
		"bind '$' command-prompt -I'#S' \"rename-session -- '%%'\"",
 | 
			
		||||
		"bind % split-window -h",
 | 
			
		||||
		"bind & confirm-before -p\"kill-window #W? (y/n)\" kill-window",
 | 
			
		||||
		"bind \"'\" command-prompt -pindex \"select-window -t ':%%'\"",
 | 
			
		||||
		"bind ( switch-client -p",
 | 
			
		||||
		"bind ) switch-client -n",
 | 
			
		||||
		"bind , command-prompt -I'#W' \"rename-window -- '%%'\"",
 | 
			
		||||
		"bind - delete-buffer",
 | 
			
		||||
		"bind . command-prompt \"move-window -t '%%'\"",
 | 
			
		||||
		"bind 0 select-window -t:=0",
 | 
			
		||||
		"bind 1 select-window -t:=1",
 | 
			
		||||
		"bind 2 select-window -t:=2",
 | 
			
		||||
		"bind 3 select-window -t:=3",
 | 
			
		||||
		"bind 4 select-window -t:=4",
 | 
			
		||||
		"bind 5 select-window -t:=5",
 | 
			
		||||
		"bind 6 select-window -t:=6",
 | 
			
		||||
		"bind 7 select-window -t:=7",
 | 
			
		||||
		"bind 8 select-window -t:=8",
 | 
			
		||||
		"bind 9 select-window -t:=9",
 | 
			
		||||
		"bind : command-prompt",
 | 
			
		||||
		"bind \\; last-pane",
 | 
			
		||||
		"bind = choose-buffer -Z",
 | 
			
		||||
		"bind ? list-keys",
 | 
			
		||||
		"bind D choose-client -Z",
 | 
			
		||||
		"bind E select-layout -E",
 | 
			
		||||
		"bind L switch-client -l",
 | 
			
		||||
		"bind M select-pane -M",
 | 
			
		||||
		"bind [ copy-mode",
 | 
			
		||||
		"bind ] paste-buffer",
 | 
			
		||||
		"bind c new-window",
 | 
			
		||||
		"bind d detach-client",
 | 
			
		||||
		"bind f command-prompt \"find-window -Z -- '%%'\"",
 | 
			
		||||
		"bind i display-message",
 | 
			
		||||
		"bind l last-window",
 | 
			
		||||
		"bind m select-pane -m",
 | 
			
		||||
		"bind n next-window",
 | 
			
		||||
		"bind o select-pane -t:.+",
 | 
			
		||||
		"bind p previous-window",
 | 
			
		||||
		"bind q display-panes",
 | 
			
		||||
		"bind r refresh-client",
 | 
			
		||||
		"bind s choose-tree -Zs",
 | 
			
		||||
		"bind t clock-mode",
 | 
			
		||||
		"bind w choose-tree -Zw",
 | 
			
		||||
		"bind x confirm-before -p\"kill-pane #P? (y/n)\" kill-pane",
 | 
			
		||||
		"bind z resize-pane -Z",
 | 
			
		||||
		"bind '{' swap-pane -U",
 | 
			
		||||
		"bind '}' swap-pane -D",
 | 
			
		||||
		"bind '~' show-messages",
 | 
			
		||||
		"bind PPage copy-mode -u",
 | 
			
		||||
		"bind -r Up select-pane -U",
 | 
			
		||||
		"bind -r Down select-pane -D",
 | 
			
		||||
		"bind -r Left select-pane -L",
 | 
			
		||||
		"bind -r Right select-pane -R",
 | 
			
		||||
		"bind M-1 select-layout even-horizontal",
 | 
			
		||||
		"bind M-2 select-layout even-vertical",
 | 
			
		||||
		"bind M-3 select-layout main-horizontal",
 | 
			
		||||
		"bind M-4 select-layout main-vertical",
 | 
			
		||||
		"bind M-5 select-layout tiled",
 | 
			
		||||
		"bind M-n next-window -a",
 | 
			
		||||
		"bind M-o rotate-window -D",
 | 
			
		||||
		"bind M-p previous-window -a",
 | 
			
		||||
		"bind -r S-Up refresh-client -U 10",
 | 
			
		||||
		"bind -r S-Down refresh-client -D 10",
 | 
			
		||||
		"bind -r S-Left refresh-client -L 10",
 | 
			
		||||
		"bind -r S-Right refresh-client -R 10",
 | 
			
		||||
		"bind -r DC refresh-client -c",
 | 
			
		||||
		"bind -r M-Up resize-pane -U 5",
 | 
			
		||||
		"bind -r M-Down resize-pane -D 5",
 | 
			
		||||
		"bind -r M-Left resize-pane -L 5",
 | 
			
		||||
		"bind -r M-Right resize-pane -R 5",
 | 
			
		||||
		"bind -r C-Up resize-pane -U",
 | 
			
		||||
		"bind -r C-Down resize-pane -D",
 | 
			
		||||
		"bind -r C-Left resize-pane -L",
 | 
			
		||||
		"bind -r C-Right resize-pane -R",
 | 
			
		||||
		"bind -N 'Send the prefix key' C-b send-prefix",
 | 
			
		||||
		"bind -N 'Rotate through the panes' C-o rotate-window",
 | 
			
		||||
		"bind -N 'Suspend the current client' C-z suspend-client",
 | 
			
		||||
		"bind -N 'Select next layout' Space next-layout",
 | 
			
		||||
		"bind -N 'Break pane to a new window' ! break-pane",
 | 
			
		||||
		"bind -N 'Split window vertically' '\"' split-window",
 | 
			
		||||
		"bind -N 'List all paste buffers' '#' list-buffers",
 | 
			
		||||
		"bind -N 'Rename current session' '$' command-prompt -I'#S' \"rename-session -- '%%'\"",
 | 
			
		||||
		"bind -N 'Split window horizontally' % split-window -h",
 | 
			
		||||
		"bind -N 'Kill current window' & confirm-before -p\"kill-window #W? (y/n)\" kill-window",
 | 
			
		||||
		"bind -N 'Prompt for window index to select' \"'\" command-prompt -pindex \"select-window -t ':%%'\"",
 | 
			
		||||
		"bind -N 'Switch to previous client' ( switch-client -p",
 | 
			
		||||
		"bind -N 'Switch to next client' ) switch-client -n",
 | 
			
		||||
		"bind -N 'Rename current window' , command-prompt -I'#W' \"rename-window -- '%%'\"",
 | 
			
		||||
		"bind -N 'Delete the most recent paste buffer' - delete-buffer",
 | 
			
		||||
		"bind -N 'Move the current window' . command-prompt \"move-window -t '%%'\"",
 | 
			
		||||
		"bind -N 'Describe key binding' '/' command-prompt -kpkey 'list-keys -1N \"%%%\"'",
 | 
			
		||||
		"bind -N 'Select window 0' 0 select-window -t:=0",
 | 
			
		||||
		"bind -N 'Select window 1' 1 select-window -t:=1",
 | 
			
		||||
		"bind -N 'Select window 2' 2 select-window -t:=2",
 | 
			
		||||
		"bind -N 'Select window 3' 3 select-window -t:=3",
 | 
			
		||||
		"bind -N 'Select window 4' 4 select-window -t:=4",
 | 
			
		||||
		"bind -N 'Select window 5' 5 select-window -t:=5",
 | 
			
		||||
		"bind -N 'Select window 6' 6 select-window -t:=6",
 | 
			
		||||
		"bind -N 'Select window 7' 7 select-window -t:=7",
 | 
			
		||||
		"bind -N 'Select window 8' 8 select-window -t:=8",
 | 
			
		||||
		"bind -N 'Select window 9' 9 select-window -t:=9",
 | 
			
		||||
		"bind -N 'Prompt for a command' : command-prompt",
 | 
			
		||||
		"bind -N 'Move to the previously active pane' \\; last-pane",
 | 
			
		||||
		"bind -N 'Choose a paste buffer from a list' = choose-buffer -Z",
 | 
			
		||||
		"bind -N 'List key bindings' ? list-keys -N",
 | 
			
		||||
		"bind -N 'Choose a client from a list' D choose-client -Z",
 | 
			
		||||
		"bind -N 'Spread panes out evenly' E select-layout -E",
 | 
			
		||||
		"bind -N 'Switch to the last client' L switch-client -l",
 | 
			
		||||
		"bind -N 'Clear the marked pane' M select-pane -M",
 | 
			
		||||
		"bind -N 'Enter copy mode' [ copy-mode",
 | 
			
		||||
		"bind -N 'Paste the most recent paste buffer' ] paste-buffer",
 | 
			
		||||
		"bind -N 'Create a new window' c new-window",
 | 
			
		||||
		"bind -N 'Detach the current client' d detach-client",
 | 
			
		||||
		"bind -N 'Search for a pane' f command-prompt \"find-window -Z -- '%%'\"",
 | 
			
		||||
		"bind -N 'Display window information' i display-message",
 | 
			
		||||
		"bind -N 'Select the previously current window' l last-window",
 | 
			
		||||
		"bind -N 'Toggle the marked pane' m select-pane -m",
 | 
			
		||||
		"bind -N 'Select the next window' n next-window",
 | 
			
		||||
		"bind -N 'Select the next pane' o select-pane -t:.+",
 | 
			
		||||
		"bind -N 'Select the previous pane' p previous-window",
 | 
			
		||||
		"bind -N 'Display pane numbers' q display-panes",
 | 
			
		||||
		"bind -N 'Redraw the current client' r refresh-client",
 | 
			
		||||
		"bind -N 'Choose a session from a list' s choose-tree -Zs",
 | 
			
		||||
		"bind -N 'Show a clock' t clock-mode",
 | 
			
		||||
		"bind -N 'Choose a window from a list' w choose-tree -Zw",
 | 
			
		||||
		"bind -N 'Kill the active pane' x confirm-before -p\"kill-pane #P? (y/n)\" kill-pane",
 | 
			
		||||
		"bind -N 'Zoom the active pane' z resize-pane -Z",
 | 
			
		||||
		"bind -N 'Swap the active pane with the pane above' '{' swap-pane -U",
 | 
			
		||||
		"bind -N 'Swap the active pane with the pane below' '}' swap-pane -D",
 | 
			
		||||
		"bind -N 'Show messages' '~' show-messages",
 | 
			
		||||
		"bind -N 'Enter copy mode and scroll up' PPage copy-mode -u",
 | 
			
		||||
		"bind -N 'Select the pane above the active pane' -r Up select-pane -U",
 | 
			
		||||
		"bind -N 'Select the pane below the active pane' -r Down select-pane -D",
 | 
			
		||||
		"bind -N 'Select the pane to the left of the active pane' -r Left select-pane -L",
 | 
			
		||||
		"bind -N 'Select the pane to the right of the active pane' -r Right select-pane -R",
 | 
			
		||||
		"bind -N 'Set the even-horizontal layout' M-1 select-layout even-horizontal",
 | 
			
		||||
		"bind -N 'Set the even-vertical layout' M-2 select-layout even-vertical",
 | 
			
		||||
		"bind -N 'Set the main-horizontal layout' M-3 select-layout main-horizontal",
 | 
			
		||||
		"bind -N 'Set the main-vertical layout' M-4 select-layout main-vertical",
 | 
			
		||||
		"bind -N 'Select the tiled layout' M-5 select-layout tiled",
 | 
			
		||||
		"bind -N 'Select the next window with an alert' M-n next-window -a",
 | 
			
		||||
		"bind -N 'Rotate through the panes in reverse' M-o rotate-window -D",
 | 
			
		||||
		"bind -N 'Select the previous window with an alert' M-p previous-window -a",
 | 
			
		||||
		"bind -N 'Move the visible part of the window up' -r S-Up refresh-client -U 10",
 | 
			
		||||
		"bind -N 'Move the visible part of the window down' -r S-Down refresh-client -D 10",
 | 
			
		||||
		"bind -N 'Move the visible part of the window left' -r S-Left refresh-client -L 10",
 | 
			
		||||
		"bind -N 'Move the visible part of the window right' -r S-Right refresh-client -R 10",
 | 
			
		||||
		"bind -N 'Reset so the visible part of the window follows the cursor' -r DC refresh-client -c",
 | 
			
		||||
		"bind -N 'Resize the pane up by 5' -r M-Up resize-pane -U 5",
 | 
			
		||||
		"bind -N 'Resize the pane down by 5' -r M-Down resize-pane -D 5",
 | 
			
		||||
		"bind -N 'Resize the pane left by 5' -r M-Left resize-pane -L 5",
 | 
			
		||||
		"bind -N 'Resize the pane right by 5' -r M-Right resize-pane -R 5",
 | 
			
		||||
		"bind -N 'Resize the pane up' -r C-Up resize-pane -U",
 | 
			
		||||
		"bind -N 'Resize the pane down' -r C-Down resize-pane -D",
 | 
			
		||||
		"bind -N 'Resize the pane left' -r C-Left resize-pane -L",
 | 
			
		||||
		"bind -N 'Resize the pane right' -r C-Right resize-pane -R",
 | 
			
		||||
 | 
			
		||||
		"bind -n MouseDown1Pane select-pane -t=\\; send-keys -M",
 | 
			
		||||
		"bind -n MouseDrag1Border resize-pane -M",
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user