# tmux swap-window

Source: https://libtmux.org/en/tmux/3.7c/manual/swap-window/

> This is similar to link-window, except the source and destination windows are swapped.

This is similar to link-window, except the source and destination windows are swapped.

## Syntax

```tmux-usage
tmux swap-window [-d] [-s src-window] [-t dst-window]
```

Alias: `swapw`.

## Behavior

This is similar to [`link-window`](https://libtmux.org/en/tmux/3.7c/manual/link-window/), except the source and destination windows are swapped. It is an error if no window exists at `src-window`. If `-d` is given, the new window does not become the current window.

If `-s` is omitted and a marked pane is present (see [`select-pane`](https://libtmux.org/en/tmux/3.7c/manual/select-pane/) `-m`), the window containing the marked pane is used rather than the current window.

## C implementation

Internal declarations in tmux 3.7c:

* [`cmd_swap_window_entry`](https://libtmux.org/en/tmux/3.7c/reference/c-variable-cmd_swap_window_entry/)
* [`cmd_swap_window_exec`](https://libtmux.org/en/tmux/3.7c/reference/c-function-cmd-swap-window-c-cmd_swap_window_exec/)

## Use from a library

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

* [Python](https://libtmux.org/en/py/latest/reference/libtmux-window-swap/)
* [TypeScript](https://libtmux.org/en/ts/latest/reference/window-window-swapwith/)
* [Rust](https://libtmux.org/en/rs/latest/reference/window-window-swap_with/)
* [Go](https://libtmux.org/en/go/latest/reference/tmux-window-swap/)
* [C#](https://libtmux.org/en/csharp/latest/reference/libtmux-window-swapasync/)
* [C++](https://libtmux.org/en/cxx/latest/reference/libtmux-window-swap_with/)
* [Swift](https://libtmux.org/en/swift/latest/reference/server-swap\(_-with-\)/)
* [Lua](https://libtmux.org/en/lua/latest/reference/libtmux-windowlink-swap/)

tmux sources and license

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

Behavior is taken from the [tmux 3.7c manual](https://github.com/tmux/tmux/blob/79072dd1a9f5fb437a5859e362a496fd57ec0981/tmux.1).

[Command declaration](https://github.com/tmux/tmux/blob/79072dd1a9f5fb437a5859e362a496fd57ec0981/cmd-swap-window.c#L32)

```
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.
```
