# tmux_window_link:swap/3

- **Package:** libtmux_erlang
- **Language:** Erlang
- **Kind:** function
- **Source:** https://github.com/libtmux/libtmux-erlang/blob/d1b6308440cf9eb8f6647e7ae434bce60e849368/apps/libtmux_erlang/src/tmux_window_link.erl#L109
- **Page:** https://libtmux.org/en/erlang/latest/reference/tmux_window_link-swap-3/

```
swap(Source, Destination, Options)
-spec swap(tmux_model:window_link(),
           tmux_model:window_link(),
           swap_options()) ->
              {ok, tmux_operation:completed()} |
              {error, tmux_operation:failure()}.
```

Swap the physical windows at two checked memberships. Other links to either window remain intact. detach maps to tmux -d and defaults true. tmux applies its session-selection and group-synchronization rules. Returns the command result; old rows still name their original expected windows and can become stale. Performs I/O, with the documented gap between preflight and action.

## Parameters

- `Source` (`tmux_model:window_link()`)
- `Destination` (`tmux_model:window_link()`)
- `Options` (`swap_options()`)

## tmux command

The tmux commands behind `swap/3`.

- [`swap-window`](/en/tmux/latest/manual/swap-window/)

## tmux C API

The C declarations in tmux that implement these commands.

- [`cmd_swap_window_entry`](/en/tmux/latest/reference/c-variable-cmd_swap_window_entry/) (attribute)
- [`cmd_swap_window_exec`](/en/tmux/latest/reference/c-function-cmd-swap-window-c-cmd_swap_window_exec/) (function)

## In other ports

Exchange two windows

| Language | Equivalent |
| --- | --- |
| Python | [`libtmux.Window.swap`](/en/py/latest/reference/libtmux-window-swap/) (method) |
| Lua | [`libtmux.WindowLink:swap`](/en/lua/latest/reference/libtmux-windowlink-swap/) (method) |
| Haskell | No public Haskell equivalent is implemented; the current modules expose scalar values and version parsing. |
| TypeScript | [`window.Window.swapWith`](/en/ts/latest/reference/window-window-swapwith/) (method) |
| Rust | [`window.Window.swap_with`](/en/rs/latest/reference/window-window-swap_with/) (method) |
| Go | [`tmux.Window.Swap`](/en/go/latest/reference/tmux-window-swap/) (method) |
| Java | no equivalent on `Window` |
| C# | [`LibTmux.Window.SwapAsync`](/en/csharp/latest/reference/libtmux-window-swapasync/) (method) |
| C++ | [`libtmux::Window::swap_with`](/en/cxx/latest/reference/libtmux-window-swap_with/) (method) |
| Swift | [`Server.swap(_:with:)`](/en/swift/latest/reference/server-swap(_-with-)/) (method) |
| OCaml | No direct public OCaml equivalent is recorded for this operation. |
| Perl | No dedicated equivalent in the selected Perl surface. Explicit Server::cmd remains available for native tmux commands. |

No equivalent is recorded in Ruby, PowerShell, Julia, Elixir, Common Lisp, Clojure, Kotlin, Scala or F#.
