Skip to content
/
Try

Copy and paste over SSH to your local clipboard (OSC 52)

Ctrl+D for the next match, Alt+Shift+↓ for the line below.

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> BEL

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.

  1. Use a terminal that supports OSC 52. Most modern terminals accept OSC 52 writes, some only after you enable it (see the table below).

  2. Let programs inside tmux set the clipboard. Add this to ~/.tmux.conf, then run tmux source-file ~/.tmux.conf:

    ~/.tmux.conf
    set -g set-clipboard on
  3. Turn it on in your editor. Neovim detects it, Skink does it by default, and Vim, Helix and Micro need a setting (below).

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.

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.

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.lua
vim.g.clipboard = "osc52"
vim.opt.clipboard = "unnamedplus" -- optional: make y and p use the system clipboard

Vim ships an optional osc52 package that works with its clipboard provider support:

" ~/.vimrc
packadd osc52
set clipmethod+=osc52

On older Vim builds, use a plugin such as vim-oscyank.

~/.config/helix/config.toml
[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.

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.

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.

Terminal window
ssh you@server
curl -fsSL https://skink.cc/install.sh | sh
skink notes.md
# select a line, Ctrl+C, then paste on your laptop

More: SSH and remote editing guide, the best terminal editor for SSH.