# libtmux.Window.swap

- **Module:** libtmux
- **Package:** libtmux
- **Language:** Python
- **Kind:** method
- **Source:** https://github.com/tmux-python/libtmux/blob/38e368c11117fb4aeb2f082d552cd4f210eae06a/src/libtmux/window.py#L1129
- **Page:** https://libtmux.org/en/py/stable/reference/libtmux-window-swap/

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

```
libtmux.Window.swap(
    self, target: str | Window, detach: bool | None = None
) -> None
```

Swap this window with another via [`$ tmux swap-window`](/en/tmux/latest/manual/swap-window/).

## Examples

```python
>>> w1 = session.new_window(window_name='swap_a')
>>> w2 = session.new_window(window_name='swap_b')
>>> w1_idx = w1.window_index
>>> w2_idx = w2.window_index
>>> w1.swap(w2)
>>> w1.window_index == w2_idx
True
>>> w2.window_index == w1_idx
True
```

## Parameters

- `target` (`str | Window`): Target window to swap with. Can be a window ID string or Window.
- `detach` (`bool | None`): Do not change the active window (``-d`` flag).

## In other ports

### Exchange two windows

- Lua: [`libtmux.WindowLink:swap`](/en/lua/latest/reference/libtmux-windowlink-swap/) (method)
- 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)
- 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)
