Neovim 101 — OSC 52
Let’s check out Operating System Command (OSC) and OSC 52.

In this article, we will learn the basics of OSC (Operating System Command), and how to use OSC 52 to transport data from a remote SSH session to the local system clipboard.
This article is part of the Neovim 101 series.
The Neovim configuration files are available in this repository.
Getting Started
In the previous article on terminal and shell, we talked about Control Sequence Introducer (CSI), and how to configure Alacritty, Kitty, and WezTerm to enable CSI u which uses control sequences starting with ESC [ or \x9B.
In this article, we will go through OSC which uses control sequences starting with ESC ] or \x9D.
OSC
OSC stands for Operating System Command. Originally OSC sequences were defined by Xterm, but many are also supported by other modern terminal emulators, e.g., Alacritty, Kitty, and WezTerm.
Let’s go through several examples.
The following command sets the style to the bold and red foreground.
\x1b[— the escape sequence1— the bold color/graphic mode. Refer to this table for details31— the red color code. Refer to this table for details
print "\x1b[1;31mHello Alpha2Phi"
In general, the command looks like this
ESC[{graphic mode};{color code};{...}mLet’s look at another example.
print "\x1b[3;30;44mHello Alpha2Phi"
- For the graphic mode, we set it to italic (3)
- For the text foreground color, we set it to black (30)
- For the text background color, we set it to blue (44)
OSC 52
OSC can be used to configure the window title, text background/foreground color, cursor shape, clipboard operation, screen mode, keyboard settings, etc.
For Neovim, we will focus on OSC 52 sequence that can be used to manipulate the clipboard operations.
ESC]52;c;[base64 data]\aOSC 52 is particularly useful when we want to copy selected data from a remote SSH session to the local system clipboard.
For example, from a remote SSH session, we can use the following alias to copy data from the remote host to the local system clipboard.
alias clip="base64 | xargs -0 printf '\e]52;c;%s\007'"Let’s try this out using an AWS EC2 instance.
Scenario — AWS EC2 Instance
For my projects, I need to use an AWS EC2 instance daily.
In the screenshot below, we use Alacritty to ssh to the AWS EC2 instance using the following command.
ssh -i /path/key-pair-name.pem instance-user-name@instance-public-dns-name
Alacritty supports OSC 52, and we can use the OSC 52 control sequence to copy data from the AWS EC2 instance to the local computer clipboard.

In the screenshot above, in the left window, we copy the data using OSC 52 in the remote host and paste the copied data into the local console in the right window.
Chromium Project
The Chromium project provides useful scripts to test out OSC 52, including a Vim plugin.
For example, we can use the osc52.sh script to copy data from a remote host.

Plugins
There are plugins available for Vim and Neovim that we can use to copy data from a remote host.
From the server, once we install the plugins, any yanked text from within Neovim is made available to the local host.
nvim-osc52
nvim-osc52 is a Neovim plugin to copy text to the system clipboard using the ANSI OSC 52 sequence.
We install this plugin using packer.nvim.








