Copy to clipboard from tmux on a remote ssh session · Gaganpreet Arora
Note: A better approach is documented in this blog post by Igor Babuschkin.
My current working setup is tmux + neovim. On top of that, I use my desktop for development that I often access remotely outside of home.
One of the drawbacks of working remotely via SSH was that I couldn’t copy to my client’s native clipboard (eg: to share code snippets in Slack) remotely.
It took me some time to figure out how to do it, and it’s quite straightforward.
With Wayland, this won't work, indeed. My new setup relies on OSC-52.
Edit: the post has been updated with the solution below.
Click here to open
I have this in my neovim config:
```lua
local function paste()
return {
vim.fn.split(vim.fn.getreg(""), "\n"),
vim.fn.getregtype(""),
}
end
vim.g.clipboard = {
name = "OSC 52",
copy = {
["+"] = require("vim.ui.clipboard.osc52").copy("+"),
["*"] = require("vim.ui.clipboard.osc52").copy("*"),
},
paste = {
["+"] = paste,
["*"] = paste,
},
}
vim.opt.clipboard:append { 'unnamed', 'unnamedplus' }
```
And these two in my tmux config:
```
set -s set-clipboard on
set -g allow-passthrough
```
This only works with a supported terminal emulator which supports OSC-52 (I use Kitty)
Copy to clipboard from tmux on a remote ssh session · Gaganpreet Arora
My current working setup is tmux + neovim. On top of that, I use my desktop for development that I often access remotely outside of home. One of the drawbacks of working remotely via SSH was that I couldn’t copy to my client’s native clipboard (eg: to share code snippets in Slack) remotely. It took me some time to figure out how to do it, and it’s quite straightforward.
https://gaganpreet.in/posts/tmux-ssh-remote-clipboard/