21

Copy from Remote Server to Local Clipboard via OSC 52 in Neovim

 3 years ago
source link: https://jdhao.github.io/2021/01/05/nvim_copy_from_remote_via_osc52/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Copy from Remote Server to Local Clipboard via OSC 52 in Neovim

2021-01-05264 words 2 mins read 10 times read

In my daily work, I usually log into a remote server via a terminal emulator and do my development work there. Sometimes, I need to copy text from remote server to my local machine’s clipboard. Previously, I use mouse to select and copy the text, which I find to be quite cumbersome.

What is OSC 52

Recently, I have found out the OSC 52 terminal sequence1, which is really useful when we want to copy text from remote to local clipboard.

We can use OSC 52 sequence to tell terminal emulator that we want to put some text into the clipboard of local machine. The actual text is base64 encoded. If the terminal emulator supports it, then it can decode the text and put it into the system clipboard.

Set up OSC 52 support in Mintty terminal

On Windows, mintty terminal as old as version 2.6.1 supports this feature. Mintty config is in directory C: \Users\Administrator\AppData\Roaming\mintty, and the name is config. Open the file and add the following option:

AllowSetSelection=yes

Restart mintty and this feature will take effect. To verify, log into the remote server using mintty terminal, and run the following command:

printf "\033]52;c;$(printf "%s" "hello" | base64)\a"

Now your local clipboard content should become “hello”.

Copy text inside Neovim to local clipboard

With terminal’s support for OSC 52, we can copy text from Neovim to our local clipboard directly.

Install vim-oscyank:

Plug 'ojroques/vim-oscyank'

Select a text region and use command OSCYank to copy the text to your local clipboard.

Author jdhao

LastMod 2021-01-05

License CC BY-NC-ND 4.0

Reward
Concurrent.futures in Python

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK