My current pane resize mapping are

bind Left resize-pane -L 5
bind Down resize-pane -D 5
bind Up resize-pane -U 5
bind Right resize-pane -R 6

I have to type the key binding strokes and the arrow keys to resize the pane each time. That's stupid. How to into some sort of the resizing pane mode and only tapping the key arrows till the size is satisfied and then exit the resize pane mode.

What will be the command/key mapping for your to "Enter the pan and can change size by only the arrow key mode" and "Exit this mode"


migrated from vi.stackexchange.com Aug 17 '18 at 11:26

This question came from our site for people using the vi and Vim families of text editors.


Using existing keys

You might not need to add anything to your configuration at all. Here are the default bindings for resizing the panes (from :list-keys):

bind-key -r -T prefix M-Up             resize-pane -U 5
bind-key -r -T prefix M-Down           resize-pane -D 5
bind-key -r -T prefix M-Left           resize-pane -L 5
bind-key -r -T prefix M-Right          resize-pane -R 5
bind-key -r -T prefix C-Up             resize-pane -U
bind-key -r -T prefix C-Down           resize-pane -D
bind-key -r -T prefix C-Left           resize-pane -L
bind-key -r -T prefix C-Right          resize-pane -R

That -r option to bind-key means they support repeat -- you can keep hitting C-Arrow or M-Arrow until you've finished resizing, without entering the prefix sequence again. The amount of time before this repeat mode times out is controlled by the repeat_time option (default 500ms).

Binding with no prefix

If you want to avoid the prefix key entirely, you can use a different bind table. From the bind-key section of the manpage:

By default (without -T), the key is bound in the prefix key table. This table is used for keys pressed after the prefix key (for example, by default 'c' is bound to new-window in the prefix table, so 'C-b c' creates a new window). The root table is used for keys pressed without the prefix key: binding 'c' to new-window in the root table (not recommended) means a plain 'c' will create a new window. -n is an alias for -T root.

To bind directly into the root table:

bind-key -n C-Up resize-pane -U 5
bind-key -n C-Down resize-pane -D 5
bind-key -n C-Left resize-pane -L 5
bind-key -n C-Right resize-pane -R 5

Binding in copy mode

You suggested a dedicated mode for resizing. tmux has no support for such custom modes, but it already has copy mode (by default, entered with prefix-[ and left with q) in which keypresses can have different bindings, typically without the prefix. Unfortunately, binding multiword commands (including commands with arguments) in this mode isn't supported (see tmux issue 215). However, there is a workaround of testing #{pane_in_mode} before doing anything. Based on the comments on that issue, and the above "bind with no prefix" solution:

bind-key -n C-Up if-shell -F "#{pane_in_mode}" "resize-pane -U 5" "send-keys C-Up"
bind-key -n C-Down if-shell -F "#{pane_in_mode}" "resize-pane -D 5" "send-keys C-Down"
bind-key -n C-Left if-shell -F "#{pane_in_mode}" "resize-pane -L 5" "send-keys C-Left"
bind-key -n C-Right if-shell -F "#{pane_in_mode}" "resize-pane -R 5" "send-keys C-Right"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.