How to resize a pane to occupy a certain percentage of a whole tmux window?

Viewed 2325

I recently started to use tmux and likes it a lot. I'd like to know how to set the size of my panes using percentage. For example, there are 3 panels in a row, and I'd like to set the 1 pane to occupy 20% of the window width, and the other 2 panes each occupy 40% of the window width. But so far, I could only find commands below.

Ctrl+B Alt+Arrow
- Resize the active pane

resize-pane -R 20
-  Resizes the pane right by 20 cells

Any better ways to do it?

1 Answers

There is no -p flag for resize-pane, which is what you are really after, although it has been on the todo list for a while. Instead you will need to use -x or -y and work out the sizes yourself, for example a shell script like:

W=$(tmux display -p '#{window_width}')
L=$(expr $W \* 2 / 10)
R=$(expr $W \* 4 / 10)
tmux resizep -t{left} -x $L
tmux resizep -t{right} -x $R

Another alternative would be to set up a layout like you want then get the layout string (you can see it in "tmux lsw"), then you can reapply it to a different window with the same number of panes using "tmux selectl ...").

Related