惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
月光博客
月光博客
博客园 - 三生石上(FineUI控件)
The Cloudflare Blog
博客园 - Franky
IT之家
IT之家
V
Visual Studio Blog
博客园 - 【当耐特】
阮一峰的网络日志
阮一峰的网络日志
V
V2EX
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 司徒正美
爱范儿
爱范儿
Hugging Face - Blog
Hugging Face - Blog
宝玉的分享
宝玉的分享
博客园 - 叶小钗
有赞技术团队
有赞技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
酷 壳 – CoolShell
酷 壳 – CoolShell
量子位
罗磊的独立博客
小众软件
小众软件
Jina AI
Jina AI

jdhao's digital space

Conversion between base64 and OpenCV or PIL Image 腾讯云对象存储博客图床开启 CDN 加速(不需要购买额外域名) Search and Replace in Multiple Files in Vim/Neovim Change Table Column Width in LaTeX Image or Table Side by Side in LaTeX LaTeX 并排显示图像或表格 Firenvim: Neovim inside Your Browser Content inside HTML tags missing in Latest Hugo? Creating Markdown Front Matter with Ultisnips Labelme JSON 标注格式转 voc XML 格式 Nifty Nvim Techniques That Make My Life Easier -- Series 6 macOS 下如何为视频制作字幕 Running Command Asynchronously inside Neovim Resolving Merge Conflict after Git Stash Pop Pylint: command not found? A Hands-on Experience with Neovim's Built-in LSP Support How to Convert PDF to Images with Imagemagick 互联网上常用缩略语集锦 File Backup in Neovim Converting PDF Pages to Images with Poppler Nifty Nvim Techniques That Make My Life Easier -- Series 5 Neovim Configuration for System-wide Use How to sort a list of tuple or list in Python -- lambda or itemgetter? Building A Vim Statusline from Scratch 人类第一颗原子弹爆炸始末 Distributed Training in PyTorch with Horovod Learning Expect Programming Essential Knowledge about SSH Nifty LaTeX Techniques -- Series 1 更改 Adsense 邮寄地址,重新寄送 PIN
Copy from Remote Server to Local Clipboard via OSC 52 in ...
2021-01-05 · via jdhao's digital space

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:

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”.

Enable OSC 52 support in ZOC terminal#

ZOC terminal has added support for OSC-52 terminal sequence in version 8.01.0, as indicated by its change log.

To enable this feature, go to Options --> Edit Session Profile, in the Advanced section, we need to activate the following option:

Activate control sequences that enable remote hosts to execute commands locally.

Currently, osc-52 in ZOC only works for pure ASCII characters and does not work for non-ASCII characters. The dev said that it will be fixed in the next release.

Enable OSC 52 in iterm2#

Open preferences, and go to General settings. Turn on the option Applications in terminal may access clipboard. It’s off by default for security reasons.

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.

References#