ojroques / nvim-osc52

A Neovim plugin to copy text through SSH with OSC52
BSD 2-Clause "Simplified" License
349 stars 12 forks source link

osc52 does not copy to tmux clipboard #6

Closed miversen33 closed 2 years ago

miversen33 commented 2 years ago

Hello! I am having an odd issue in that I cannot seem to get osc52 to copy to tmux's system clipboard. I have verified that the tmux clipboard does work as I can copy things from neovim with tmux itself, but that is obviously painful.

I am using the default config in the readme

require('osc52').setup {
  max_length = 0,  -- Maximum length of selection (0 for no limit)
  silent = false,  -- Disable message on successful copy
  trim = false,    -- Trim text before copy
}

local function copy(lines, _)
  require('osc52').copy(table.concat(lines, '\n'))
end

local function paste()
  return {vim.fn.split(vim.fn.getreg(''), '\n'), vim.fn.getregtype('')}
end

vim.g.clipboard = {
  name = 'osc52',
  copy = {['+'] = copy, ['*'] = copy},
  paste = {['+'] = paste, ['*'] = paste},
}

-- Now the '+' register will copy to system clipboard using OSC52
vim.keymap.set('n', '<leader>c', '"+y')
vim.keymap.set('n', '<leader>cc', '"+yy')

Specifically, my config can be found here

ojroques commented 2 years ago

Hello, have you tried these steps first to enable osc52 in tmux?

https://github.com/tmux/tmux/wiki/Clipboard#quick-summary

Also what is your tmux version?

miversen33 commented 2 years ago

Below is the details from my tmux details. I have previously used oscyank and had no issues, but I seem to be running into some weirdness in migrating to osc52 :/

$ tmux show -s set-clipboard
set-clipboard external

$ tmux info | grep Ms
180: Ms: (string) \033]52;%p1%s;%p2%s\a

$ echo $TERM
xterm-256color

$ tmux -V
tmux 3.0a
miversen33 commented 2 years ago

To add to this, I can also confirm that the above configuration works fine if I am not running tmux.

Fine being, I can yank and it goes to my system clipboard. So this appears to be localized within how osc52 is talking to tmux

ojroques commented 2 years ago

I managed to reproduce your issue. It seems that external does not work, instead use:

set -s set-clipboard on

Here's a post explaining why on works but not external: https://unix.stackexchange.com/questions/560428/what-is-the-difference-between-the-values-off-and-external-for-the-set-clip.

Feel free to reopen the issue if your problem persists :)

miversen33 commented 2 years ago

Thats really weird. I can confirm that on fixed the issue. I wonder, any idea why external worked with oscyank but not with nvim-osc52?

ojroques commented 2 years ago

It's because vim-oscyank handled tmux differently than other terminals to support old versions of tmux also. This plugin treats it the same as others but therefore is not compatible with older versions.

miversen33 commented 2 years ago

Ahh that makes sense. You're awesome, I appreciate you :)

lherman-cs commented 1 year ago

I have the same issue, but setting tmux clipboard to on doesn't fix the problem.

$ tmux show -s set-clipboard
set-clipboard on

$ tmux info | grep Ms
192: Ms: (string) \033]52;%p1%s;%p2%s\a

$ echo $TERM
xterm-256color

$ tmux -V
tmux 3.3a
lherman-cs commented 1 year ago

@ojroques

ojroques commented 1 year ago

What terminal are you using? Do you know if it supports the OSC52 sequence?

lherman-cs commented 1 year ago

I'm using Alacritty. I have solved the issue, I need to add this to my .tmux.conf, set-option -ag terminal-overrides ",xterm-256color:Ms=\\E]52;c;%p2%s\\7".

Thanks for the plugin ^^

SonglinLife commented 1 year ago

I encountered the same problem. Thanks to this issue, I simply used "set -s set-clipboard on" and solve it. :pray: