Giter Site home page Giter Site logo

vim-tmux-yank's Introduction

Vim Tmux Yank

This is a simple plugin for synchronizing the clipboards of vim/nvim, tmux, and a variety of operating systems, even over remote connections. It does so via a terminal escape called OSC 52.

There are other ways to accomplish similar things; you can e.g. use xclip, wl-copy, clip.exe, pbcopy. However, this requires different utilities on different systems, and doesn't always work over ssh. Notably, many hosts disable X forwarding for security reasons, many headless servers don't have X installed, and Wayland or WSL users may not want an X server just to get basic clipboard functionality. OSC 52, in contrast, works transparently over ssh and across platforms.

Quickstart

This plugin assumes you use vim or nvim inside of tmux, and wish to synchronize your clipboards in tmux, vim/nvim, and your operating system. You can install this plugin using a standard vim plugin manager like vim-plug:

Plug 'jabirali/vim-tmux-yank'

Then enable OSC 52 on the tmux side, just add this to your tmux.conf:

set -g set-clipboard on

This is sufficient to integrate your vim and tmux clipboards. Some terminals like Alacritty set your operating system clipboard by default when an OSC 52 code is intercepted, others like iTerm reportedly require you to enable this feature in the settings. If you now yank text in vim (try e.g. Vy or yy), the yanked text should be available from your vim clipboard, tmux clipboard, and operating system clipboard. It should automatically work over ssh too.

This plugin lets you yank to your tmux and system clipboards, but you cannot paste via terminal escape codes. This is arguably a good thing: I don't mind servers I ssh into writing to my clipboard, but letting them read it is a privacy concern. Pasting content copied outside vim is perhaps best done using your terminal keyboard shortcut (I map it to Alt+p).

Acknowledgements

Almost all of this code was copied from Leeren's post on Reddit, so all credit should go to them. The only thing I added was the tmux tty check.

I tried some existing OSC-52 plugins, and none of them seemed to work on Neovim. According to Google, no-one else had wrapped this code as a plugin. To streamline things for other users like me, I therefore wrapped it as a plugin myself.

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.