A Vim / Neovim plugin to copy text to the system clipboard from anywhere using the ANSI OCS52 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 November 2020):
|GNOME Terminal (and other VTE-based terminals)||not yet|
call plug#begin() Plug 'ojroques/vim-oscyank' call plug#end()
Enter Visual mode, select your text and run
You may want to map the command:
vnoremap <leader>c :OSCYank<CR>
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'
If you prefer to copy text from a particular register, use:
nnoremap <leader>c :call YankOSC52(getreg('+'))<CR> " will copy text from register '+'
You can also define an autocommand to immediately copy after a yank operation (use
v:event.regname is '' for the unnamed register):
augroup OSCYank autocmd! autocmd TextYankPost * \ if v:event.operator is 'y' && v:event.regname is '+' | :call YankOSC52(getreg('+')) | endif augroup END
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 makes the maximum length of strings configurable.
- It supports kitty which has a slightly modified OSC52 protocol by default.
- It does not mandate users to overwrite their default register (
The code is derived from hterm's script.