Neovim 101 — OSC 52

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

alpha2phi

--

Neovim 101 — 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 sequence
  • 1 — the bold color/graphic mode. Refer to this table for details
  • 31 — 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};{...}m

Let’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

--

--

alpha2phi

Software engineer, Data Science and ML practitioner.