Copy and paste over SSH to your local clipboard (OSC 52)
To copy from a program on a remote server to your local clipboard, use OSC 52. It is an escape sequence that a program prints to the terminal; your local terminal decodes it and sets your clipboard.
It travels over SSH like any other output, so no X11 forwarding or extra tools are needed. Three things have to agree: your terminal, tmux (if you use it), and the editor.
The sequence itself looks like this:
ESC ] 52 ; c ; <base64 text> BELWhy doesn’t copy work over SSH?
Section titled “Why doesn’t copy work over SSH?”When you yank in Vim on a server, the text goes to the server’s clipboard. That usually does not exist (no X11 or Wayland session), or it is not yours.
Tools like xclip or pbcopy on the server cannot reach your laptop. OSC 52 skips all of that by sending the text through the terminal connection you already have.
Set up OSC 52 copy
Section titled “Set up OSC 52 copy”-
Use a terminal that supports OSC 52. Most modern terminals accept OSC 52 writes, some only after you enable it (see the table below).
-
Let programs inside tmux set the clipboard. Add this to
~/.tmux.conf, then runtmux source-file ~/.tmux.conf:~/.tmux.conf set -g set-clipboard on -
Turn it on in your editor. Neovim detects it, Skink does it by default, and Vim, Helix and Micro need a setting (below).
Terminals that support OSC 52
Section titled “Terminals that support OSC 52”| Terminal | OSC 52 copy |
|---|---|
| Kitty, WezTerm, Ghostty, Alacritty, foot, Windows Terminal | Supported |
| iTerm2 | Supported; enable “Applications in terminal may access clipboard” in preferences |
| xterm | Supported, off by default (enable it in X resources) |
| GNOME Terminal and other VTE-based terminals | Historically not supported; check your version |
Reading the clipboard through OSC 52 (paste) is often disabled for security. That is fine: for paste, use your terminal’s own paste key.
Why tmux needs set-clipboard
Section titled “Why tmux needs set-clipboard”tmux sits between the program and your terminal. Since tmux 2.6 the default set-clipboard external lets tmux itself set the clipboard, but blocks programs inside it from doing so. set -g set-clipboard on allows them.
If it still does not reach your terminal, your tmux may not know the terminal can do it. Adding set -as terminal-features ',*:clipboard' tells it to assume so.
OSC 52 settings per editor
Section titled “OSC 52 settings per editor”Neovim (0.10+)
Section titled “Neovim (0.10+)”In the terminal UI, Neovim detects OSC 52 support and uses it when no other clipboard tool is found. Force it when detection picks the wrong thing, for example over SSH where a server-side tool exists, or inside tmux:
-- init.luavim.g.clipboard = "osc52"vim.opt.clipboard = "unnamedplus" -- optional: make y and p use the system clipboardVim (recent 9.1 patches)
Section titled “Vim (recent 9.1 patches)”Vim ships an optional osc52 package that works with its clipboard provider support:
" ~/.vimrcpackadd osc52set clipmethod+=osc52On older Vim builds, use a plugin such as vim-oscyank.
[editor]clipboard-provider = "termcode"{ "clipboard": "terminal" }nano has no OSC 52 support. Use your terminal’s own selection: hold Shift while dragging if the mouse is enabled.
How Skink does it
Section titled “How Skink does it”Skink sends OSC 52 on every copy and cut by default, alongside the system clipboard when there is one. There is nothing to configure.
- Ctrl+C copies the selection (or the line with no selection), Ctrl+X cuts.
- In the file tree, y copies the absolute path and Shift+Y the relative one, through the same route.
- Programs running in Skink’s terminal tabs can use OSC 52 too (for example an AI CLI’s “copy” command); Skink forwards their requests to your terminal.
- With multiple cursors, copy puts one line per cursor on the clipboard.
Inside tmux you still need set -g set-clipboard on, as for any program.
How do I paste from my laptop into the remote editor?
Section titled “How do I paste from my laptop into the remote editor?”Use your terminal’s paste shortcut, for example Ctrl+Shift+V on Linux, Cmd+V on macOS, or right-click in Windows Terminal.
The terminal sends the text as a bracketed paste. Editors that support it (Vim, Neovim, Helix, Micro, Skink) insert it as one block without auto-indenting each line.
What about X11 forwarding?
Section titled “What about X11 forwarding?”ssh -X (or -Y) with xclip on the server can share an X11 clipboard. But it needs an X server locally, it is slower, and it widens what the server can do to your desktop.
OSC 52 is simpler and safer for copy.
Try it
Section titled “Try it”ssh you@servercurl -fsSL https://skink.cc/install.sh | shskink notes.md# select a line, Ctrl+C, then paste on your laptopMore: SSH and remote editing guide, the best terminal editor for SSH.