da2x / vim-oscyank

A Vim plugin to copy text through SSH with OSC52

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

vim-oscyank

A Vim / Neovim plugin to copy text to the system clipboard from anywhere using the ANSI OSC52 sequence.

When this sequence is emitted by Vim, the terminal will copy the given text into the system clipboard. This is totally location independent, users can copy from anywhere including from remote SSH sessions.

The only requirement is that the terminal must support the sequence. Here is a non-exhaustive list of the status of popular terminal emulators regarding OSC52 (as of June 2022):

Terminal OSC52 support
Alacritty yes
foot yes
GNOME Terminal (and other VTE-based terminals) not yet
hterm (Chromebook) yes
iTerm2 yes
kitty yes
Konsole not yet
screen yes
st yes (but needs to be enabled, see here)
Terminal.app no, but see workaround
tmux yes
Windows Terminal yes
rxvt yes (to be confirmed)
urxvt yes (with a script, see here)
xterm.js (Hyper terminal) not yet
wezterm yes

Feel free to add terminals to this list by submitting a pull request.

Installation

With vim-plug:

Plug 'ojroques/vim-oscyank', {'branch': 'main'}

Basic usage

Enter Visual mode, select your text and run :OSCYank.

You may want to map the command:

vnoremap <leader>c :OSCYank<CR>

You can also use the OSCYank operator:

nmap <leader>o <Plug>OSCYank

like so for instance:

<leader>o_   " copy the current line
<leader>oip  " copy the inner paragraph

Copying from a register

If you prefer to copy text from a particular register, use:

:OSCYankReg +  " this will copy to clipboard the text in register '+'

To copy after any yank operation:

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

Or to copy only the + register (vim's system clipboard register):

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

Configuration

By default you can copy up to 100000 characters at once. If your terminal supports it, you can raise that limit with:

let g:oscyank_max_length = 1000000

The plugin treats tmux, screen and kitty differently than other terminal emulators. The plugin should automatically detects the terminal used but you can bypass detection with:

let g:oscyank_term = 'tmux'  " or 'screen', 'kitty', 'default'

By default a confirmation message is echoed after text is copied. This can be disabled with:

let g:oscyank_silent = v:true  " or 1 for older versions of Vim

Troubleshooting

The plugin does not work with tmux

First follow this guide from tmux. If it still doesn't work, try setting set -s set-clipboard on in your tmux config and put let g:oscyank_term = 'default' in your Vim config (see issue #26).

Features

There are already Vim plugins implementing OSC52. However this plugin fixes several issues I've had with them:

  • It supports Neovim.
  • It supports Windows.
  • It does not mandate users to overwrite their unnamed register (").
  • It makes the maximum length of strings configurable.
  • It supports kitty versions below 0.22.0 which implement a slightly modified OSC52 protocol.

Credits

The code is derived from hterm's script.

hterm's LICENCE
vim-oscyank's LICENSE

About

A Vim plugin to copy text through SSH with OSC52

License:BSD 2-Clause "Simplified" License


Languages

Language:Vim Script 100.0%