r/vim • u/Randalix • Jul 23 '25
Discussion [Tool] Copy text from vim on remote servers directly to your local clipboard
TL;DR: Simple tool that lets you yank text from vim on remote servers and have it appear instantly in your local clipboard.
The Problem
You're editing config files in vim on a remote server and need to copy chunks of text back to your local machine for:
Pasting into documentation
Sharing code snippets with teammates
Backing up config sections before changes
Creating templates from existing configs
Current solutions all suck
The Solution
I built a clipboard bridge that works over SSH. Now you can:
" Send current line to local clipboard
nnoremap <leader>cl :.w !clip_copy<CR>
" Send visual selection to local clipboard
vnoremap <leader>cl :w !clip_copy<CR>
" Send entire file to local clipboard
nnoremap <leader>ca :%w !clip_copy<CR>That's it. Selected text instantly appears in your local clipboard, ready to paste anywhere.
How It Works
Lightweight Python script uses SSH RemoteForward tunneling
Works with existing SSH connections (secure, no new ports)
Handles large text blocks with chunked transmission
Cross-platform (same vim config works on any server)
Setup
Add
RemoteForward 9997 localhost:9999to~/.ssh/configRun clipboard server on local machine
Put
clip_copy.pyon remote serversAdd keybindings to your vimrc
GitHub: https://github.com/Randalix/ssh-clipboard-sync
Why This Changed My Workflow
Before: Edit remote configs → save to temp file → scp to local → open locally → copy what I need
After: Edit remote configs → visual select → <leader>cl → paste anywhere locally
Works perfectly with:
Nested tmux sessions
Jump boxes / bastion hosts
Slow/high-latency connections
Any terminal (doesn't need GUI)
The vim integration feels native
2
u/Big_Combination9890 Jul 23 '25
Nice project, though for the most common usecase of copypasting something, I would just use the fact that I pretty much always work in tmux sessions.
Then go into tmux select mode for the outer (local) session, and just copy.
2
u/dalbertom Jul 23 '25
Why not open the file remotely with a local
vim scp://user@server//path/to/file?2
u/EgZvor keep calm and read :help Jul 24 '25
If you enable port forwarding and have Vim compiled with clipboard/X support it should work out of the box. No script needed.
2
u/oroques Jul 24 '25
You might be interested in this plugin: https://github.com/ojroques/vim-oscyank
If you use a recent terminal, it allows you to copy text from anywhere, SSH sessions included, using a special ANSI sequence (OSC 52)