# window.Window.link_to

- **Module:** window.Window
- **Package:** libtmux
- **Language:** Rust
- **Kind:** method
- **Source:** https://github.com/libtmux/libtmux-rs/blob/8a648c0894dfffc9303583f753b6c8ae01f2fe76/crates/libtmux/src/window.rs#L984
- **Page:** https://libtmux.org/reference/rs/window-window-link_to/

```
window.Window.link_to(self, session: &Session, index: Option<i32>) -> Result<(), Error>
```

Link this window into another session, so both hold the same window.

A linked window is one window with two winlinks, not a copy: renaming
it or splitting it shows up in both sessions. [`Window::unlink`] takes
one link away again.

`index` places the link at a window index, or appends when `None`.

# Errors

Returns [`Error::ServerMismatch`] when `session` belongs to another
server, or an error when tmux refuses the link, including an occupied
index.

## Example

```rust
let source = server.new_session("linking-from").await?;
let target = server.new_session("linking-to").await?;
let window = source.windows().await?.remove(0);

window.link_to(&target, None).await?;

let linked = target.windows().await?;
assert!(linked.iter().any(|other| other.id() == window.id()));
```
