10

Say, I got two windows, Window 1 contains 2 pane (1, 2), Window 2 contains 3 panes(1,2,3), and I'm in pane 1 in Window 1, and I want to jump directly into the pane 2 in Window 2, PREFIX w which is choose-window will list all the windows in the session so I can jump into the right window, but it will not list the panes, PREFIX q which is display-panes will let me choose the right pane only in the current window, but not across windows.

So I wonder if there is any command that let me choose panes across windows. The best solution is choose-window or a new command will not only list all the windows but also list all the panes inside each window like tree in a directory.

4
  • 2
    list-panes -s will show all the panes in the current server, but doesn't provide a way to choose one to make active. You can probably script something that takes this output and passes it to choose-list.
    – chepner
    Aug 29, 2015 at 2:36
  • @chepner Thanks for the list-panes -s, but according to the CHANGES file in Github repo page, the choose-list has been removed, I'm using the latest version of tmux from git.
    – CodyChan
    Aug 31, 2015 at 2:09
  • Sorry about that. I must have been looking at the man page on two different machines (one apparently out of date) while trying to find if there was a feasible answer.
    – chepner
    Aug 31, 2015 at 2:39
  • (Note to self: bind-key h choose-tree, then use it with C-b h. It doesn't seem to conflict with any existing binding according to C-b :list-keys.)
    – toraritte
    May 16, 2023 at 15:04

3 Answers 3

11

This problems is solved by commit aad4e4d on github page several months ago, use choose-tree (just bind it to a key) to show all panes in all sessions/widows/tabs, it even shows a preview box when you scroll line into one pane from the list, very nice.

Just compile and install tmux from github source code and you can use this feature.

3

The command is

tmux list-panes [-a|--all]

You can access this from within a tmux session with

<prefix>: list-panes -a

For example, if you need to pass a command to all panes that have vim running, you can do something like:

    tmux list-panes -aF "#{pane_id} #{pane_current_command}" |
    awk '/vim|nvim/ {print $1}' |
    xargs -I {} tmux send-keys -t {} "C-[" ":so ~/.vimrc" "C-m"

This command does the following:

  • tmux list-panes -aF "#{pane_id} #{pane_current_command}" lists all panes across all sessions and windows, and for each pane, it prints the pane ID and the current command running in the pane.
  • awk '/vim|nvim/ {print $1}' filters the output to only include lines where the current command is either vim or nvim, and then it prints the pane ID of those panes.
  • xargs -I {} tmux send-keys -t {} C-[ ":so ~/.vimrc" C-m takes the pane IDs output by awk and for each pane ID, it sends the keys <Esc> (to ensure we're in normal mode), :so ~/.vimrc (the command to reload the vimrc file), and <Enter> (to execute the command) to that pane.
0

Any item in this list, that return the format <Session.pane_id>:

tmux list-panes -aF "#S.#D"

can be used for send-keys:

tmux send -t '<Session.pane_id>' ls Enter

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .