DEV Community

Cover image for 2 Simple Configurations to Supercharge your TMUX Setup!
Daniel Bengl for Renuo AG

Posted on • Edited on

2 Simple Configurations to Supercharge your TMUX Setup!

Tmux is a terminal multiplexer. It is a tool for managing multiple shells inside a single terminal window. It is integrated into most modern terminal emulators like Iterm2 or Warp. In this blog article, I will show you two simple configurations that drastically improved my tmux experience.

Autoresizing panes

The main problem I had with tmux when starting out was that panes were not automatically resized as I was used from Warp:

Managing window panes in tmux with auto-resizing not configured.

Don't get confused by the remapped tmux prefix. The main thing to notice here is that I am using <PREFIX> + E to spread the panes out evenly.

What we now need is:

  1. The command to resize the windows
  2. The hook(s) for executing the command
  3. Update the tmux configuration with the hook and the command.

Part1: Finding the command

According to the manual entry for tmux:

select-layout [-Enop] [-t target-pane] [layout-name]
                             (alias: selectl)
                 Choose a specific layout for a window.  If layout-name is not given, the last preset layout used (if any) is
                 reapplied.  -n and -p are equivalent to the next-layout and previous-layout commands.  -o applies the last
                 set layout if possible (undoes the most recent layout change).  -E spreads the current pane and any panes
                 next to it out evenly.
Enter fullscreen mode Exit fullscreen mode

We can use the select-layout -E command to spread the panes evenly.

Part2: Finding the hooks

The first part is done. Now we need the hooks.

Unsurprisingly, this can also be found in the manual entry:

%window-pane-changed window-id pane-id
     The active pane in the window with ID window-id changed to the pane with ID pane-id.

...

window-resized          Run when a window is resized.  This may be after the client-resized hook is run.
Enter fullscreen mode Exit fullscreen mode

Part3: Updating the configuration file

If you haven't moved the .tmux.conf to .config, you can find the default configuration file for MacOS at ~/.tmux.conf.

To execute the command on the resize and pane changed hooks, we can add these lines to the tmux configuration:

# .tmux.conf
...
set-hook -g window-pane-changed 'select-layout -E'
set-hook -g client-resized 'select-layout -E'
...
Enter fullscreen mode Exit fullscreen mode

This is how the panes behave after adjusting the configuration:

Creating window panes in tmux with auto-resizing configured.

According to the manual entry, we can also shorten the command to the following:

set-hook -g window-pane-changed 'selectl -E'
set-hook -g client-resized 'selectl -E'
Enter fullscreen mode Exit fullscreen mode

Dimming Inactive Panes

Next to automatically resizing windows, we can also automatically dim panes that aren't active by using the following configuration:

set-hook -g pane-focus-out 'select-pane -P bg=colour233,fg=colour10'
set-hook -g pane-focus-in 'select-pane -P bg=default,fg=default'
Enter fullscreen mode Exit fullscreen mode

Switching panes in tmux with dimming enabled.

Now, this is a much nicer alternative than the active border color. If you are wondering how I got rid of it, I used this configuration:

set -g pane-active-border-style "bg=#000000,fg=white"
set -g pane-border-style "bg=#000000,fg=white"
Enter fullscreen mode Exit fullscreen mode

Remember that black and #000000 are not the same thing when configuring your terminal, as the color names are defined by your color scheme.

Conclusion

While tmux isn't as usable/powerful out of the box as the integrated tmux in Iterm or Warp, with some simple configuration, it can be significantly improved. The manual page for tmux is the go to source for looking up commands and events and will save a lot of time googling.

Tools and Sources

Top comments (0)