The Computer Oracle

How does one swap two panes in Tmux?

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Life in a Drop

--

Chapters
00:00 Question
00:26 Accepted answer (Score 523)
01:11 Answer 2 (Score 109)
01:38 Answer 3 (Score 75)
02:26 Answer 4 (Score 16)
02:49 Thank you

--

Full question
https://superuser.com/questions/879190/h...

Answer 2 links:
[tmux manpage]: https://www.systutorials.com/docs/linux/.../

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#keyboardshortcuts #tmux

#avk47



ACCEPTED ANSWER

Score 569


The swap-pane command can do this for you. The { and } keys are bound to swap-pane -U and swap-pane -D in the default configuration.

So, to effect your desired change, you can probably use Prefix { when you are in the right pane (or Prefix } if you are in the left pane).

The -U and -D refer to “up” and “down” in the pane index order (“up” is the same direction that Prefix o moves across panes). You can see the pane indices with display-panes (Prefix q, by default).




ANSWER 2

Score 117


You can hit Ctrl b and keep holding down Ctrl while hitting o. This will rotate all existing panes around, so in your case it will swap the only two existing panes.

Ctrl b + Alt o rotates the opposite way (useful when you have more than two panes).




ANSWER 3

Score 80


The most precise control you can have is by using the command swap-pane directly. This is not so difficult to do:

  1. ctrl-b q shows you the "ID" for each pane in current window - remember the two panes you want to swap. Let's say they're 3 and 5.
  2. ctrl-b : to activate the tmux command line. Then issue command swap-pane -s3 -t5.

Note that you have auto-completion when typing commands. Also you can search for syntax of a command directly from tmux manpage. That's how I learn the syntax for swap-pane.




ANSWER 4

Score 20


To directly swap two panes:

  1. Select the first pane with prefix m (the default for prefix is ctrl-b)
  2. Go to the second pane, and type prefix :swap-pane