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?
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 ...").
I like to work with 3 tmux panes. one horizontal pane at the upper half of the screen and two more panes at the bottom half. These panes are split vertically.
There are cases where I would like to take the last pane and make it go from top to bottom. like this:
How can I achieve this? using [ctrl+b ctrl+o] and [ctrl+b space] did not reach the desired position and is cumbersome.
There is probably an easier way, but what you can do is arrange the panes manually in each of the two configurations, noting each layout in a variable with e.g.:
layout1=$(tmux list-windows -F '#{window_layout}')
This holds a string something like:
5f2f,80x23,0,0[80x11,0,0,0,80x11,0,12{39x11,0,12,1,40x11,40,12,2}]
which you must not alter in any way as the first number is a checksum of the rest of the string.
Once you have the two strings you can set a binding to set that layout using select-layout, or by giving the command from the shell where you have the variables:
tmux select-layout "$layout1"
You might find it easier to write a small helper script, say mtmux to toggle between the layouts:
#!/usr/bin/bash
# https://stackoverflow.com/q/56343223/5008284
# toggle between 2 layouts, previously saved
layout1='5f2f,80x23,0,0[80x11,0,0,0,80x11,0,12{39x11,0,12,1,40x11,40,12,2}]'
layout2='093c,80x23,0,0{39x23,0,0[39x11,0,0,0,39x11,0,12,4],40x23,40,0,3}'
layout="$(tmux list-windows -F '#{window_layout}')"
case "$layout" in
*80x11*) new=$layout2 ;;
*) new=$layout1 ;;
esac
tmux select-layout "$new"
tmux display-panes
exit 0
and have a binding, say control-L, to run this shell:
bind-key -n C-l run-shell 'mtmux'
I have iTerm2 running with two horizontal splits, split_A and split_B.
I am attached to the same tmux sessions in split_A and in split_B.
I have one window running in the tmux session, with 2 panes, pane_A and pane_B
When I do next-pane in one of the splits, the tmux running in the other split does exactly the same and moves to the next pane. So the tmux sessions are synced.
Is there a way to display pane_A in one of the tmux sessions and pane_B in the other.
Just to make sure: pane_A and pane_B are running in the same window and same session.
|-----------------------------------|
||---------------------------------||
|| iterm2 split, tmux:windowA:1 ||
||---------------------------------||
|| iterm2 split, tmux:windowA:0 ||
||---------------------------------||
|-----------------------------------|
Just because panes do not have names, so I would like to have the top tmux names console and the bottom files and their session called DEV.
DEV > CONSOLE (top split)
DEV > FILES (bottom split)
Apologies for the horrible ASCII art.
Thinking about the goal of tmux, I believe there is no way to do what your described. In addition, it seems to me that in this case you can go with one iterm window + two tmux panes, simple and easy. Why you split iterm in the first place?
How do I accomplish
[press C-a q] -> [me selecting one of the pane indices] -> [C-a z (to zoom)]
with just first two steps?
In other words, I want to rebind C-a q <NUMBER> so that the at the end, the selected pane is automatically zoomed in
I think this solution should work, put the following line in your .tmux.conf:
bind q choose-window "select-window -t '%%'; resize-pane -Z"
Then reload it by executing this command from the shell: tmux source ~/.tmux.conf
Note a couple things:
This has been tested on latest tmux version 1.9a. It might as well work on earlier versions (but I haven't tested).
Selecting a window is interactive! You can either press a <NUMBER> to select a window or use keyboard arrows to choose window.
Zooming feature will *toggle* zoom in the target window! So if the target window is already zoomed, it will get un-zoomed.
Writing prose in a console environment I like to have my editor in a narrow centered pane. I can achieve this with this .screenrc:
focusminsize 75 25
split -v
focus
only
split -v
split -v
focus
caption string "%{= dd} "
sorendition "="
Then $screen emacs gives me the desired layout.
How do I achieve something similar in tmux 1.8?
Bonus: how to I bind toggling 'default layout' / 'narrow centered single pane' to a key?