ojroques / vim-oscyank

A Vim plugin to copy text through SSH with OSC52
BSD 2-Clause "Simplified" License
615 stars 38 forks source link

Has Tmux recently changed how it supports OSC52? #26

Closed tombh closed 2 years ago

tombh commented 2 years ago

Thanks for your work on this plugin. You'll be pleased to know that any editor code here was pasted thanks to it 🤓

Curiously I couldn't get it to work out of the box with my setup.

alacritty 0.10.1 (2844606d)
tmux next-3.4
NVIM v0.8.0-dev+124-g815b65d77

I tried vim.g.oscyank_term = 'screen', which worked but could only copy a few characters. So I updated the plugin's get_OSC52_tmux function to:

function! s:get_OSC52_tmux(str)
  let b64 = s:b64encode(a:str, 0)
  return "\e]52;c;" . b64 . "\x07\e\\"
endfunction

Here's the change side by side:

"\ePtmux;\e\e]52;c;" . b64 . "\x07\e\\"
          "\e]52;c;" . b64 . "\x07\e\\"

I don't know why I need something different? Is it because I'm using such recent versions of my alacritty, tmux, nvim? Here's what I think are the relevant lines from my tmux.conf:

set -g default-terminal "tmux"
set -g set-clipboard on
set -ga terminal-overrides ",xterm-256color:RGB"

I'm happy to help more, provide more debugging etc if it's useful.

ojroques commented 2 years ago

Sorry I was away for a while. Maybe this is related to your issue: #20.

tombh commented 2 years ago

I had seen that one already. The difference is that yanking isn't working at all, for any amount of text.

farzadmf commented 2 years ago

I can confirm this as well. I think (not sure tho) it happened when I upgraded to tmux 3.3, but yeah, the yank stopped working unfortunately 🙁

ojroques commented 2 years ago

Try using this option then: let g:oscyank_term = 'default'. It fall backs to the default OSC yank instead of the special case of tmux.

farzadmf commented 2 years ago

Try using this option then: let g:oscyank_term = 'default'.

That seems to do the trick for me. Thank you @ojroques

However, do you know what could be causing the issue? It seems that my local vim is working fine even without setting the option (using tmux), but the remote vim (ssh and tmux) seems to work only when the option is set

arooni commented 2 years ago

I can't seem to get this working on mac os x + neovim 0.5.1 + tmux 3.3.

Without tmux it works great!

I did try the default option listed above but couldn't get it working.

1337G4mer commented 2 years ago

Same boat

My versions:

Mac OSX - v12.3.1
neovim - v0.7.0
tmux - 3.3
alacritty - 0.10.1 (2844606)

init.vim has

" start - oscyank plugin conf
let g:oscyank_term = 'default'
augroup Yanker
     autocmd!
     autocmd TextYankPost * if v:event.operator is 'y' && v:event.regname is '' | execute 'OSCYankReg "' | endif
augroup END
" end oscyank plugin conf

I tried with the term var as tmux and kitty as well along with default with no luck.

Let me know if any other information is needed.

Edit: Tried without tmux as done by @arooni above, and it works. Is this a tmux issue or oscyank issue?

ojroques commented 2 years ago

I'm not familiar with tmux but I'll take a look later. I've found this official guide to set up OSC52 in tmux, maybe it'll be helpful: https://github.com/tmux/tmux/wiki/Clipboard#the-set-clipboard-option. Then after following the guide, you can try again let g:oscyank_term = 'default' if it still doesn't work.

1337G4mer commented 2 years ago

Yeah read it essentially it asks to check two things...

❯ tmux show -s set-clipboard
set-clipboard external

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

Followed by let g:oscyank_term = 'default' in neovim .

Still doesn't work.

However, reading that page further seems like tmux 3.2 and later has a new tmux option copy-command I am not using it at the moment but wonder if things changed internally that's messing with this plugin

adonis0147 commented 2 years ago

I met the same issue recently and fixed it by let g:oscyank_term = 'default'. It seems that it is tmux causing the issue after I upgraded the version to the latest version (3.3).

adonis0147 commented 2 years ago

Hi @1337G4mer , try set -s set-clipboard on in tmux.conf.

1337G4mer commented 2 years ago

I was able to get it to work couple days back by trying few articles on the internet. I unfortunately can't remember how exactly I got it to work though. Bu your suggestion @adonis0147 maybe helpful for future travelers here. As far my issues goes its resolved.

arooni commented 2 years ago

Echoing the previous comment; the

set -s set-clipboard on

I previously had the following which does not work.

set -g -s set-clipboard

that combined with

let g:oscyank_term = 'default'. seems to make everything work in vim.

1337G4mer commented 2 years ago

I was able to get it to work couple days back by trying few articles on the internet. I unfortunately can't remember how exactly I got it to work though. Bu your suggestion @adonis0147 maybe helpful for future travelers here. As far my issues goes its resolved.

This fix I had was apparently lost when I did the tmux kil-server

Had to run basically this again set -s set-clipboard on like you guys said and it started working again. Now its in my .tmux.conf file for permannecy

tardypad commented 2 years ago

I stumble upon this issue myself and I believe the reason for the plugin now breaking with tmux 3.3 is the following tmux change reported in the Changelog Add an option (default off) to control the passthrough escape sequence with the option documented as follow

 allow-passthrough [on | off]
         Allow programs in the pane to bypass tmux using a terminal escape sequence (\ePtmux;...\e\\).

And this escape sequence is what this plugin is using by default when run within tmux

So with default tmux and vim configs, the sequence is being filtered out by tmux 3.3. To make this plugin work with tmux 3.3, one has to allow-passthrough on in their tmux config, or let g:oscyank_term = 'default' in their vim config to not use the special tmux handling (but then tmux has to detect that the terminal is supporting OSC52 via the Ms capability in the terminfo, otherwise it will filter it out too)

ojroques commented 2 years ago

Thanks a lot @tardypad! I've updated the README with a link to your comment.