Skip to content

A Vim plugin to copy text from anywhere with OSC52

License

Notifications You must be signed in to change notification settings

shijialee/vim-oscyank

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 

Repository files navigation

vim-oscyank

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):

Terminal OCS52 support
Alacritty yes
GNOME Terminal (and other VTE-based terminals) not yet
hterm (Chromebook) yes
iTerm2 yes
kitty yes
screen yes
tmux yes
Windows Terminal yes
rxvt yes (to be confirmed)
urxvt yes (with a script, see here)
wezterm yes

Installation

Using vim-plug:

call plug#begin()
Plug 'ojroques/vim-oscyank'
call plug#end()

Usage

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

You may want to map the command:

vnoremap <leader>c :OSCYank<CR>

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

:OSCYankReg +  " will copy text from register '+'

You can also define an autocommand to immediately copy after a yank operation (for the unnamed register ", use v:event.regname is ''):

autocmd TextYankPost * if v:event.operator is 'y' && v:event.regname is '+' | 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'

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 which has a slightly modified OSC52 protocol by default.

Credits

The code is derived from hterm's script.

hterm's LICENCE
LICENSE

About

A Vim plugin to copy text from anywhere with OSC52

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Vim Script 100.0%