'emacs Terminal control-esc-% ("query-replace-regex") ignore the "control" and yields plain meta-% (query-replace)

macOS Monterey 12.2.1. Using the built-in emacs from Terminal, I often want to do query-replace-regexp. According to GNU docs, the shortcut is C-M %, so I type control-Esc %. But emacs doesn't notice the control key. Instead it gives me the non-regex query-replace, as if I had just typed Esc % (M %).

When I type control-Esc, the command buffer at the bottom of the emacs window shows just ESC, whereas I had expected to see something like C-ESC.

For other commands, like C-r for search, C-( to learn a macro, etc the control key works just fine.

Has anybody seen this behaviour, or could suggest how I can make C-M % work?



Solution 1:[1]

I don't know about Mac, but you're probably running into a similar situation: terminal applications depend on your terminal emulator sending the adequate escape sequences for keys with modifiers. Frequently, they will not differentiate between M- and C-M-, so there's nothing Emacs can do on its side. The same happens with me on Linux, on the Tilix terminal emulator.

Unless you have some really specific needs, I'd recommend running emacs in GUI mode. Here's a really opinionated article about GUI vs terminal emacs.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Leonardo Dagnino