Tag and kill several Tmux windows
At the end of the day I usually end up with a lot of windows in my Tmux session, each with one or sometimes two panes (I have almost never more than two panes in any of my Tmux window).
Usually I don't want to kill my entire Tmux session, so I have to close the windows I won't be needing the next day.
Tmux tree mode
For this, the Tmux tree mode is very useful.
Tmux tree mode displays a list to browse sessions, windows and panes in the upper part of the window.
In the lower part of the window Tmux tree mode displays a part of the pane(s) of the current window. Using the up and down arrow keys, or j and k if you activated vi mode, selects other windows in the list and shows the pane(s) of those windows.
This is an easy way to search for a certain pane, but is also useful for other actions.
The list starts with sessions expanded so windows are shown and with the current window in the attached session selected.
O (shift-o) reverses the sort order.
You can tag items in the tree with
the tag, so hitting
t again will untag the
T (shift-t) untags all tagged items, and
Ctrl-t tags all times in the list.
The default key binding for switching to
tree mode is
My Tmux configuration binds
This means that
Ctrl-A w switches to tree mode.
After selecting one or more windows with
can kill all tagged windows with
This will kill the tagged windows including all the panes in the tagged windows.
Wrapping it up, this means, at the end of the day, I do:
Ctrl-A w ... tag windows with t X