# tmux choose-tree

Source: https://libtmux.org/en/tmux/3.2a/manual/choose-tree/

> Put a pane into tree mode, where a session, window or pane may be chosen interactively from a tree.

Put a pane into tree mode, where a session, window or pane may be chosen interactively from a tree.

## Syntax

```tmux-usage
tmux choose-tree [-GNrswZ] [-F format] [-f filter] [-K key-format] [-O sort-order] [-t target-pane] [template]
```

## Behavior

Put a pane into tree mode, where a session, window or pane may be chosen interactively from a tree. Each session, window or pane is shown on one line. A shortcut key is shown on the left in brackets allowing for immediate choice, or the tree may be navigated and an item chosen or otherwise manipulated using the keys below. `-s` starts with sessions collapsed and `-w` with windows collapsed. `-Z` zooms the pane. The following keys may be used in tree mode:

|                                                                  |                                                                          |
| ---------------------------------------------------------------- | ------------------------------------------------------------------------ |
| [**Key**](https://libtmux.org/en/tmux/3.2a/manual/full/#Key~2)   | [**Function**](https://libtmux.org/en/tmux/3.2a/manual/full/#Function~2) |
| [`Enter`](https://libtmux.org/en/tmux/3.2a/manual/full/#Enter~2) | Choose selected item                                                     |
| [`Up`](https://libtmux.org/en/tmux/3.2a/manual/full/#Up~2)       | Select previous item                                                     |
| [`Down`](https://libtmux.org/en/tmux/3.2a/manual/full/#Down~2)   | Select next item                                                         |
| [`+`](https://libtmux.org/en/tmux/3.2a/manual/full/#+)           | Expand selected item                                                     |
| `-`                                                              | Collapse selected item                                                   |
| [`M-+`](https://libtmux.org/en/tmux/3.2a/manual/full/#M-+)       | Expand all items                                                         |
| [`M--`](https://libtmux.org/en/tmux/3.2a/manual/full/#M--)       | Collapse all items                                                       |
| [`x`](https://libtmux.org/en/tmux/3.2a/manual/full/#x~2)         | Kill selected item                                                       |
| [`X`](https://libtmux.org/en/tmux/3.2a/manual/full/#X~2)         | Kill tagged items                                                        |
| [`<`](https://libtmux.org/en/tmux/3.2a/manual/full/#_)           | Scroll list of previews left                                             |
| [`>`](https://libtmux.org/en/tmux/3.2a/manual/full/#_~2)         | Scroll list of previews right                                            |
| [`C-s`](https://libtmux.org/en/tmux/3.2a/manual/full/#C-s~2)     | Search by name                                                           |
| [`m`](https://libtmux.org/en/tmux/3.2a/manual/full/#m)           | Set the marked pane                                                      |
| [`M`](https://libtmux.org/en/tmux/3.2a/manual/full/#M)           | Clear the marked pane                                                    |
| [`n`](https://libtmux.org/en/tmux/3.2a/manual/full/#n~2)         | Repeat last search                                                       |
| [`t`](https://libtmux.org/en/tmux/3.2a/manual/full/#t~2)         | Toggle if item is tagged                                                 |
| [`T`](https://libtmux.org/en/tmux/3.2a/manual/full/#T~3)         | Tag no items                                                             |
| [`C-t`](https://libtmux.org/en/tmux/3.2a/manual/full/#C-t~2)     | Tag all items                                                            |
| [`:`](https://libtmux.org/en/tmux/3.2a/manual/full/#:)           | Run a command for each tagged item                                       |
| [`f`](https://libtmux.org/en/tmux/3.2a/manual/full/#f~3)         | Enter a format to filter items                                           |
| [`H`](https://libtmux.org/en/tmux/3.2a/manual/full/#H)           | Jump to the starting pane                                                |
| [`O`](https://libtmux.org/en/tmux/3.2a/manual/full/#O~2)         | Change sort field                                                        |
| [`r`](https://libtmux.org/en/tmux/3.2a/manual/full/#r~2)         | Reverse sort order                                                       |
| [`v`](https://libtmux.org/en/tmux/3.2a/manual/full/#v~3)         | Toggle preview                                                           |
| [`q`](https://libtmux.org/en/tmux/3.2a/manual/full/#q~2)         | Exit mode                                                                |

After a session, window or pane is chosen, ‘`%%`’ is replaced by the target in `template` and the result executed as a command. If `template` is not given, "switch-client -t '%%'" is used.

`-O` specifies the initial sort field: one of ‘`index`’, ‘`name`’, or ‘`time`’. `-r` reverses the sort order. `-f` specifies an initial filter: the filter is a format - if it evaluates to zero, the item in the list is not shown, otherwise it is shown. If a filter would lead to an empty list, it is ignored. `-F` specifies the format for each item in the tree and `-K` a format for each shortcut key; both are evaluated once for each line. `-N` starts without the preview. `-G` includes all sessions in any session groups in the tree rather than only the first. This command works only if at least one client is attached.

## C implementation

Internal declarations in tmux 3.2a:

* [`cmd_choose_tree_entry`](https://libtmux.org/en/tmux/3.2a/reference/c-variable-cmd_choose_tree_entry/)
* [`cmd_choose_tree_exec`](https://libtmux.org/en/tmux/3.2a/reference/c-function-cmd-choose-tree-c-cmd_choose_tree_exec/)

## Use from a library

Each API describes its own defaults, errors and execution model.

* [Python](https://libtmux.org/en/py/latest/reference/libtmux-pane-choose_tree/)
* [TypeScript](https://libtmux.org/en/ts/latest/reference/pane-pane-choosetree/)
* [Go](https://libtmux.org/en/go/latest/reference/tmux-pane-choosetree/)
* [C#](https://libtmux.org/en/csharp/latest/reference/libtmux-pane-choosetreeasync/)

tmux sources and license

Syntax comes from `tmux 3.2a list-commands`. See the [global options](https://libtmux.org/en/tmux/3.2a/manual/full/#DESCRIPTION) for sockets and configuration, and [command syntax and targets](https://libtmux.org/en/tmux/3.2a/manual/full/#COMMANDS).

Behavior is taken from the [tmux 3.2a manual](https://github.com/tmux/tmux/blob/85893888497c5077979bc7557fb970ee5e3d13d9/tmux.1).

[Command declaration](https://github.com/tmux/tmux/blob/85893888497c5077979bc7557fb970ee5e3d13d9/cmd-choose-tree.c#L30)

```
Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>

Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
```
