An editor, a log viewer, and a shell can stay open in separate tmux windows within the same session. Selecting a window brings its panes to the foreground so keyboard input reaches the intended program.
tmux identifies each window by an index within its session. Switching windows leaves the programs in the other windows running, without moving panes or changing the client's session.
The shell commands need an existing session with at least two windows. They work inside or outside an attached client, provided the shell uses the same user account and tmux server as the session.
Steps to select a tmux window:
- List the windows in the target tmux session.
$ tmux list-windows -t work 0: shell* (1 panes) [80x24] [layout b25d,80x24,0,0,0] @0 (active) 1: logs (1 panes) [80x24] [layout b25e,80x24,0,0,1] @1 2: monitor (1 panes) [80x24] [layout b25f,80x24,0,0,2] @2
The session is named work here; for another session, replace work with its name. The number before each colon is the window index, and * marks the current window.
Related: How to list tmux sessions - Select window 1 in the work session.
$ tmux select-window -t work:1
The target work:1 selects window 1, named logs, in the work session. Success produces no output. A numeric index avoids ambiguous matches when window names are similar or duplicated.
Inside an attached client, the keyboard alternative for window 1 is Ctrl+b, release both keys, then 1. The default number bindings cover 0 through 9; a custom prefix replaces Ctrl+b.
- Confirm that the target window is now active.
$ tmux list-windows -t work 0: shell- (1 panes) [80x24] [layout b25d,80x24,0,0,0] @0 1: logs* (1 panes) [80x24] [layout b25e,80x24,0,0,1] @1 (active) 2: monitor (1 panes) [80x24] [layout b25f,80x24,0,0,2] @2
The * and (active) markers now identify logs. The - after shell marks the previously selected window. An attached client viewing work now displays the target window; if the markers still identify another window, the selection has not reached the intended target.