Thank you for visiting!
My little window on internet allowing me to share several of my passions
Categories:
- Nvim
- FreeBSD
- OpenBSD
- Firewall
- got
- PEKwm
- Zsh
- VM
- High Availability
- vdcron
- My Sysupgrade
- FreeBSD
- Nas
- VPN
- DragonflyBSD
- fapws
- Alpine Linux
- Openbox
- Desktop
- Security
- yabitrot
- nmctl
- Tint2
- Project Management
- Hifi
- Alarm
Most Popular Articles:
Last Articles:
NVIM easy copy/paste even if inside an ssh connection
Posted on 2026-03-12 19:18:00 from Vincent in Nvim
I run nvim on all my machines — my laptop running FreeBSD with Alacritty as my terminal, and several OpenBSD and FreeBSD servers I connect to via SSH. Everything works great, except for one long-standing annoyance: copy/paste in nvim on the servers was completely broken. I kept getting a message complaining about xclip missing. Of course it's missing — it's a server, I'm not going to install X11 clipboard utilities on it.
This blog post explain what to do. It's very simple, we we know it ;)

Fixing nvim clipboard over SSH with OSC 52
The fix turned out to be simpler than I expected, and requires zero changes on the laptop side.
What's actually happening
When you copy something in nvim, it tries to use your system clipboard. On a desktop, it does this by calling an external tool like xclip or xsel. Over SSH, there's no display, no X11, so those tools don't exist — and nvim has nothing to hand off to.
What we want instead is OSC 52. It's a terminal escape sequence that tells the terminal emulator "put this in the clipboard". The sequence travels back through the SSH connection to Alacritty on my laptop, and Alacritty handles the actual clipboard operation locally. No xclip needed on the server. No X11. Nothing.
Nvim 0.10+ ships with OSC 52 support built in, so there's no plugin to install.
The config
On the server, if you don't have a nvim config yet, create one:
mkdir -p ~/.config/nvim
$EDITOR ~/.config/nvim/init.lua
Note: if you have an old init.vim file sitting around, delete it. Nvim will load either init.vim or init.lua, not both, and having both causes confusing conflicts.
Add this to init.lua:
vim.g.clipboard = {
name = 'OSC 52',
copy = {
['+'] = require('vim.ui.clipboard.osc52').copy('+'),
['*'] = require('vim.ui.clipboard.osc52').copy('*'),
},
paste = {
['+'] = require('vim.ui.clipboard.osc52').paste('+'),
['*'] = require('vim.ui.clipboard.osc52').paste('*'),
},
}
This tells nvim to use OSC 52 for both the + and * registers instead of looking for xclip.
If you want copy and paste to work transparently without having to prefix every yank with "+, add this line too:
vim.opt.clipboard = 'unnamedplus'
With that, plain yy yanks to your laptop clipboard, and p pastes from it.
How to use it
Without unnamedplus, you use the + register explicitly:
"+yyto yank the current line"+yin visual mode to yank a selection"+pto paste
To get content back into the server nvim from your laptop clipboard, paste with your terminal shortcut (Ctrl+Shift+V on most Linux/BSD terminals) rather than "+p — OSC 52 paste support is more hit or miss depending on the terminal and security settings. The copy direction is rock solid though.
Why only on the server
The config lives on the server because that's where nvim runs. OSC 52 works by nvim emitting an escape sequence to stdout. That output travels over the SSH connection back to Alacritty, which intercepts the sequence and writes to the local clipboard. Alacritty already supports OSC 52 out of the box — nothing to configure on the laptop side.
If you keep dotfiles synced across machines, you can safely add this config everywhere. It works fine on a local machine too since Alacritty handles OSC 52 there just as well.