---
title: "Copy and Paste Between Neovim and the System Clipboard"
canonical: "https://mnafshin.info/devtools/13-clipboard/"
author: "Afshin Amini"
date: 2026-11-29
---
# Copy and Paste Between Neovim and the System Clipboard

Copying a stack trace from the browser into Neovim, or a method from Neovim into a chat, should just work. It usually does, but Neovim's copy and paste are built on **registers**, named slots for text, and only two of them are connected to the system clipboard. Knowing which ones, and what Neovim needs to reach the clipboard, explains every "why didn't that paste?" moment.

## Registers and the clipboard

When you yank (copy) with `y` or delete with `d`, the text goes into a register. By default that is the unnamed register, `"`, which lives inside Neovim only. Two special registers talk to the operating system:

- `+` is the system clipboard, the one Ctrl-C and Ctrl-V use in other apps.
- `*` is the "primary selection" on Linux with X11, the text you select with the mouse and paste with the middle button. On macOS and Windows it is the same as `+`.

To use a register explicitly, type `"` and its name before the command. `"+yy` copies the current line to the clipboard, and `"+p` pastes from it.

## What LazyVim sets

Typing `"+` every time is tedious, so Neovim has the `clipboard` option. LazyVim sets it to `unnamedplus`, which makes the plain `y`, `d` and `p` use the `+` register. On your own machine that means Neovim and other apps share one clipboard.

Try it in `CatalogController.java` from module 9 of the companion code. Put the cursor on the `@GetMapping("/catalog")` line, press `yy`, and paste into a browser or chat with Ctrl-V. The line arrives. Copy a URL in the browser, go back to Neovim and press `p`; it is pasted below the cursor.

[CatalogController.java](https://github.com/mnafshin/springuniverse-code/blob/main/module-09-catalog/src/main/java/info/mnafshin/springuniverse/shop/CatalogController.java)

One side effect: with `unnamedplus`, deleting a line with `dd` also replaces the system clipboard. If that bothers you, delete into the "black hole" register with `"_dd`, or set `vim.opt.clipboard = ""` in `lua/config/options.lua` and use `"+y` when you mean it.

## Neovim needs a clipboard tool

Neovim does not talk to the clipboard by itself. It looks for a helper program and uses the first one it finds:

- **macOS:** `pbcopy` and `pbpaste`, already installed.
- **Linux on Wayland:** `wl-copy` and `wl-paste` from the `wl-clipboard` package.
- **Linux on X11:** `xclip` or `xsel`.
- **Windows:** `win32yank` or the built-in `clip` and PowerShell.

If none is found, the `+` register stays inside Neovim and nothing reaches other apps. `:checkhealth provider` shows which tool Neovim picked, or tells you that none was found. On our Linux test machine with X11, installing `xclip` was all it took.

## Over SSH

On a remote machine there is no local clipboard tool to call: `xclip` on the server would write to the server's clipboard, not yours. LazyVim therefore leaves `clipboard` empty when it detects an SSH session, through the `SSH_CONNECTION` variable. `y` and `p` then use Neovim's own register, and you copy to the clipboard on purpose with `"+y`.

Where does `"+y` go over SSH? Neovim has a provider for OSC 52, a terminal escape code that asks your local terminal to put text on your local clipboard. Neovim turns it on automatically when no other tool is found and the terminal says it supports OSC 52, as terminals such as kitty, WezTerm and iTerm2 do. We could not test this on our machine, because it needs a real terminal on the other end; check `:checkhealth provider` in your own setup.

## Inside tmux

tmux has its own paste buffers. When Neovim runs inside tmux and finds no system tool, it uses tmux as the clipboard: `"+y` stores the text in a tmux buffer, and `Ctrl-b ]` pastes it in any tmux pane. In our test, with no display and no other tool, `"+y` in Neovim landed in tmux's buffer list, which is exactly this case.

Getting that text on to your local clipboard is tmux's job. Neovim's tmux provider copies with `tmux load-buffer -w`, and with tmux 3.2 or newer the `-w` asks tmux to forward the text to the outer terminal with OSC 52. If Neovim sends OSC 52 itself instead, for example with `vim.g.clipboard = "osc52"`, tmux must allow programs to set the clipboard:

```text
set -g set-clipboard on
```

[nvim-spring-ide: extras/tmux.conf](https://github.com/mnafshin/nvim-spring-ide/blob/main/extras/tmux.conf)

Neovim's documentation warns that tmux can get in the way of OSC 52 detection. We tested the tmux buffer, not the forwarding to a local terminal, so inside tmux over SSH check `:checkhealth provider` and try a copy before relying on it. Part 14 has the rest of a tmux setup that suits Neovim.

## Recap

- `+` is the system clipboard and `*` the X11 primary selection; `"+y` and `"+p` use the clipboard explicitly.
- LazyVim sets `clipboard=unnamedplus` locally, so plain `y`, `d` and `p` share the system clipboard.
- Neovim needs a clipboard tool: `pbcopy` on macOS, `wl-clipboard` on Wayland, `xclip` or `xsel` on X11, `win32yank` on Windows; `:checkhealth provider` shows which one it uses.
- Over SSH LazyVim leaves the clipboard alone; `"+y` can reach your local clipboard through OSC 52 if your terminal supports it.
- Inside tmux without other tools, Neovim uses tmux buffers; tmux forwards them to your terminal with OSC 52, and `set -g set-clipboard on` lets programs inside tmux set the clipboard directly.

**Series: Neovim as a Java IDE.** Previous: [Dockerfiles, Compose files and Kubernetes YAML in Neovim](/devtools/12-docker-and-kubernetes-files/) · Next: [Neovim inside tmux](/devtools/14-neovim-inside-tmux/)

## Sources

Official documentation and well-known tutorials read while writing this article. The wording here is our own.

- [Neovim: provider documentation (clipboard tools and OSC 52)](https://neovim.io/doc/user/provider.html#clipboard)
- [Neovim: registers](https://neovim.io/doc/user/change.html#registers)
- [LazyVim: default options (clipboard)](https://www.lazyvim.org/configuration/general)
- [tmux wiki: Clipboard](https://github.com/tmux/tmux/wiki/Clipboard)
- [tmux.app: Neovim + tmux: navigation, true color and clipboard](https://tmux.app/doc/neovim-tmux/)
- [Skink: Copy and paste over SSH to your local clipboard (OSC 52)](https://skink.cc/articles/copy-paste-over-ssh/)
- [Milad Alizadeh: Copy from tmux/nvim to clipboard over SSH](https://mil.ad/blog/2024/remote-clipboard.html)
