Skip to main content

Julia Evans

« back to all TILs

Copying to your clipboard over SSH in vim with OSC52

I have my local vim set up to integrate with my system clipboard (so that p pastes from my system clipboard etc), but I thought it was impossible to do the same thing over SSH. It turns out that actually it is possible with an ANSI escape sequence called OSC52! A few links:

I haven’t tried this yet but it seems very cool

Dmitry Mazin also told me you can create this script on a remote host, call it pbcopy, and piping into it will copy to your clipboard! I tested it and it works.

#!/bin/bash
printf "\033]52;c;%s\007" "$(base64 | tr -d '\n')"