ojroques / vim-oscyank

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

Default to OSCYANK if SSH connection? #19

Closed ryanerwin closed 3 years ago

ryanerwin commented 3 years ago

Thanks for putting together this module.

nnoremap yy V:OSCYank<CR>
vnoremap y :OSCYank<CR>

Perhaps recommend on the main README page enabling this anytime you've got an SSH connection... Something like?

if exists('$SSH_CONNECTION')
    nnoremap yy V:OSCYank<CR>
    vnoremap y :OSCYank<CR>
else
    if has('unnamedplus')
      set clipboard=unnamedplus
    endif
endif

Anyway, awesome module. I hadn't even realized this was a possible copy mechanism until a few days ago...

ojroques commented 3 years ago

I'm glad you like it!

Well if you want to put into the clipboard any text you yank,

nnoremap yy V:OSCYank<CR>
vnoremap y :OSCYank<CR>

should work both through SSH and on local so to me there's no need to distinguish these two cases.

You can also avoid these mappings and use this autocommand instead:

autocmd TextYankPost * if v:event.operator is 'y' && v:event.regname is '' | execute 'OSCYankReg "' | endif

which allows you to copy any yanked text in all modes (yaw for instance will copy text even in normal mode).

ryanerwin commented 3 years ago

My thinking was that this method of communicating with the clipboard may be slightly higher latency or have slightly smaller data size limits, so I presumed that it made the most sense to only use this via ssh (note that mosh sessions also set the SSH_CONNECTION environment variable). I should also extended this for tmux (and screen if possible).

Keeping a consistent configuration certainly has huge benefits though!

I also had no idea about the autocmd TextYankPost. Some times I'm amazed how deep vim goes!

ojroques commented 3 years ago

Yes the only difference is that by default you cannot copy more than 1000000 characters at one. I won't update the README since it's kind of an edge case (not everyone wants the yank operation to always copy to clipboard) but I'll make sure to link people to this issue if needed. Thanks :)

vogler commented 2 years ago

Yes the only difference is that by default you cannot copy more than 1000000 characters at one.

Unlikely I'd run into it, yet still a limitation I'd like to avoid. What happens if you try to copy more?

I just added $SSH_CLIENT != '' && in your example. No point in sending those sequences if there's no receiver.

autocmd TextYankPost * if $SSH_CLIENT != '' && v:event.operator is 'y' && v:event.regname is '' | execute 'OSCYankReg "' | endif