Why was the “meta” key replaced on modern terminals?

Posted on

Problem :

I want to understand how the alt key behaves on terminals.

From some reading it appears that the “meta key” has been replaced on modern systems with sending Esc+ instead, why is that? What is the difference between meta and Esc+?

Is there a difference between what mac does vs what linux does when you hit the alt key?

Here is some discussion related to being unable to map the meta-modifier in vim because of what I’m pointing out here:



Solution :

The Alt key typically prefixes the sent symbol with the Esc character, e.g. pressing Alt+x generates the Esc (0x1B) byte followed by x.

As far as I know, traditionally the Meta key used to set the high bit, e.g. Meta+x used to generate the byte 0xF8 (x = 0x78; 0x78 + the 8th bit is 0xF8). Or maybe there used to be two different popular configurations for the Meta key: setting the 8th bit, as well emitting an Esc prefix.

Then two things happened.

One is that today’s computers no longer have a physical Meta key, so in terminal emulators running on PCs the Alt key took its role.

The other is that with the widespread adoption of Unicode (UTF-8), setting the high bit no longer makes any sense; in fact, conflicts with the encoding of pretty much any non-English letter. Applications expect the terminal to send valid UTF-8, and flipping the 8th bit would break this.

That’s how terminals ended up with the current situation of Alt (or possibly Option on Mac) emitting an Esc prefix.

Leave a Reply

Your email address will not be published. Required fields are marked *