28

Ideally, I'd like it so that I can resize panes by some margin I'd want by just pressing down on the prefix + arrow keys and watch the panel resize till a point that I'm happy with, and I'd just lift my hand to stop the resizing.

2 Answers 2

62

By default these bindings (among others) are active:

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

This means you can resize a pane by prefixAlt or prefixCtrl etc.

(The default prefix is Ctrl B.)

Thanks to -r you can do prefixCtrl without repeating prefix many times, if you strike fast enough. Holding instead of striking it repeatedly may or may not work. If it doesn't work then it means tmux does not receive the second (or later) soon enough. In this case you can:

  • Reconfigure your keyboard. E.g. in my Kubuntu the initial delay is 600 ms, which is higher than the default threshold of 500 ms used by tmux, therefore holding doesn't work by default. Then there will be 25 repeats per second, i.e. with the average interval of 40 ms, which is good enough for tmux. Changing 600 ms to 400 ms in the system-wide keyboard settings allows me to use prefixCtrl (hold).

  • Reconfigure tmux. The behavior is governed by the repeat-time option:

    repeat-time time
    Allow multiple commands to be entered without pressing the prefix-key again in the specified time milliseconds (the default is 500). Whether a key repeats may be set when it is bound using the -r flag to bind-key. Repeat is enabled for the default keys bound to the resize-pane command.

    Example command (in a shell inside tmux):

      tmux set repeat-time 1000
    

    Or in ~/.tmux.conf (permanent setting):

      set -g repeat-time 1000
    

Whichever method you choose (one or both), you want repeat-time in tmux to be higher than the delay and the repeat interval in your keyboard settings. Then you will even be able to

prefixCtrl (hold)(hold)(hold)(hold)

with just one prefix and without releasing Ctrl, if only you switch between , , and fast enough. If your prefix includes Ctrl then you don't need to release it. I mean with the default prefix of Ctrl B you can do this:

Ctrl B(hold)(hold)(hold)(hold)

holding Ctrl during the entire sequence.

7
  • 1
    I'll point out, this mentions the use of default bindings. These bindings didn't use to exist so beware, you no longer need to set them.
    – flickerfly
    Feb 24, 2022 at 14:59
  • I would like to do the same with vim hjkl, but I also have bind-key -T root M-h select-pane -L and it takes precedence over bind-key -r -T prefix M-k resize-pane -U 5, do you know how to fix that ?
    – paime
    Jul 8, 2022 at 13:18
  • @paime I don't expect M-h to get in conflict with M-k in any circumstances (h is not k, right?). But I don't experience any conflict between -T root M-h and -T prefix M-h either. Post a separate question; link to this answer if you think it provides context; include mcve, so I (or anyone) can replicate your problem. Jul 8, 2022 at 13:28
  • Copy pasted the wrong line yes. Here it is as a question: superuser.com/q/1730620/1277454
    – paime
    Jul 8, 2022 at 13:37
  • 1
    This doesn't seem to be working anymore on Apple M1 Pro 2021. The prefix C-Up/Down/Left/Right. I checked Keyboard shortcuts in Settings and didn't see anything overriding Ctrl up/down/left/right. I'm using iTerm 2 and tmux 3.2a.
    – azizj
    Aug 30 at 3:41
7

To resize tmux panes, you’ll first want to hit your prefix — ctrl + b by default — and then the colon key :. What this does is brings up a prompt at the bottom of your screen.

Now you’ll want to type in resize-pane in the prompt, followed by a hyphen - and either D, U, L, R. Which you can probably guess stands for down, up, left and right, the direction in which you want your pane to be resized. When using the resize-pane command, the resize will be applied to the last pane that had focus.

Here is an example of the entire resize pane command that resizes the pane to the left by a cell — the unit in which tmux resizes:

// This assumes that you've hit ctrl + b and : to get to the command prompt :resize-pane -L 

Here are some additional tmux pane resizing examples:

:resize-pane -D (Resizes the current pane down) 

:resize-pane -U (Resizes the current pane upward) 

:resize-pane -L (Resizes the current pane left) 

:resize-pane -R (Resizes the current pane right) 

:resize-pane -D 10 (Resizes the current pane down by 10 cells) 

:resize-pane -U 10 (Resizes the current pane upward by 10 cells) 

:resize-pane -L 10 (Resizes the current pane left by 10 cells) 

:resize-pane -R 10 (Resizes the current pane right by 10 cells) 
2
  • 5
    OP asked about using the arrow keys. Using the prompt works for resizing, but not via the arrow keys.
    – leosh
    Nov 22, 2021 at 9:17
  • This is not an answer to the question.
    – oligofren
    Oct 25 at 6:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .