The main-horizontal and main-vertical layouts in tmux are not just about dividing your screen; they’re about intelligently managing focus and providing a primary workspace.
Let’s see it in action. Imagine you’re working on a project and want to keep your main editor window large while having a terminal for running commands or checking logs on the side.
Here’s how you’d set that up:
# Start a new session
tmux new-session -d -s myproject
# Split the window horizontally for the main editor
tmux split-window -h -p 70
# Select the left pane (which is now the editor pane)
tmux select-pane -L
# Split the right pane vertically for the log viewer
tmux split-window -v -p 50
# Switch to the main-horizontal layout
tmux select-layout main-horizontal
# Now, let's say you want to prioritize a vertical terminal and a horizontal log viewer
# Re-split the current pane (which is the editor pane)
tmux split-window -v -p 50
# Switch to the main-vertical layout
tmux select-layout main-vertical
In main-horizontal, the largest pane is at the top, and subsequent panes are stacked below it, each taking up a portion of the remaining vertical space. When you add a new pane in main-horizontal, it will be created in the currently active pane, and the layout will adjust to maintain the primary top pane’s dominance.
Conversely, main-vertical prioritizes a pane on the left. The largest pane is on the left, and subsequent panes are placed to its right, each taking up a portion of the remaining horizontal space. New panes are also created in the active pane, with the layout adapting to keep the primary left pane as large as possible.
The main-horizontal layout is ideal when you have a primary task that benefits from a wide, top-aligned workspace, like a large code editor or a document, with secondary, narrower panes below for supporting information or tasks.
The main-vertical layout shines when your primary focus is a tall, left-aligned pane, such as a detailed terminal output, a debugger, or a command-line tool, with auxiliary panes to its right for less dominant but still important tasks.
When you use select-layout main-horizontal or select-layout main-vertical, tmux doesn’t just rearrange the panes; it re-evaluates the proportions. It identifies the "main" pane (top for horizontal, left for vertical) and ensures it retains its dominant size, distributing the remaining space among the other panes according to the layout’s logic. This means that even if you’ve manually resized panes, applying a main-* layout will reset them to the layout’s preferred proportions.
The key difference lies in which dimension is prioritized for the primary pane: horizontal space at the top for main-horizontal, and vertical space on the left for main-vertical.
Often, people think of tmux layouts as static divisions. However, the main-* layouts are dynamic. When you create a new pane within a session that’s already using main-horizontal or main-vertical, that new pane is automatically placed within the currently active pane, and the layout then rebalances itself to maintain the integrity of the main pane. This means you can continue to build out your workspace incrementally while still adhering to the chosen layout’s focus.
The next step is often understanding how to bind these layout changes to key commands for quick switching.