Coder Social home page Coder Social logo

vim-oscyank's Introduction

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
QTerminal 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
far2l 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

vim-oscyank's People

Contributors

ojroques avatar shijialee avatar joechrisellis avatar emersion avatar unxed avatar da2x avatar franklinyu avatar irizwaririz avatar mattysweeps avatar thiagowfx avatar zdrazil avatar hiberabyss avatar krehwell avatar qy3u avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.