Unlike GUI-based apps, terminal-based apps (like almost all of those that you run inside Terminal windows) are limited in which key combinations they can sense. Back when terminals were real hardware (not just emulated by programs like Terminal and xterm), terminals like DEC's VT-100 had a Control key, but it only worked in combination with certain other keys. Since most terminal emulation programs emulate a VT-100 (and its successors, including the VT-102 and the VT-220), there is no way to actually send a Control-Shift-5 (or whatever C-% is on your keyboard) to a terminal-based program.
You will probably have better luck mapping query-replace-regexp
to a key (combination) that actually transmits something. The ‘F keys’ are (usually) mapped in a VT-220 style that the xterm-color
termcap/terminfo entries know how to parse (F1-F4/F5 may be in a VT-100 style though!). If needed, you can configure Terminal to send whatever codes your termcap/terminfo is expecting (at least I can in the 10.4 Terminal). You can assign codes to a bare F-key or an F-key with a single modifier (Shift, Control, or Option). Any modifiers would not be passed (through the terminal) to Emacs as such, but you could map some of those combinations to the terminal key codes for higher function keys (F14-F20) (unless the combination is taken by a system shortcut—“Full Keyboard Access”, Expose, and Spaces(?)).
(global-set-key (kbd "<f13>") 'query-replace-regexp) ; I have a full-sized keyboard with an F13 on it.
Note that F1-F4 may not work properly, depending on the configuration of Terminal and emacs. For example, on my system (10.4), Terminal is configured with “ESCOP” (the VT-100 key code) for F1, but emacs expects “ESC[11~” (an ‘old’ xterm sequence). The keys work fine in emacs if I reconfigure either Terminal (⌘I; Keyboard) or emacs (see below).
; Expect VT-100 key codes for F1-F4
(define-key function-key-map "\eOP" [f1])
(define-key function-key-map "\eOQ" [f2])
(define-key function-key-map "\eOR" [f3])
(define-key function-key-map "\eOS" [f4])
Looks like you hit a known Ubuntu bug where the appmenu-gtk package seems to be broken. The solution seems to be to remove this package until this gets fixed in the repositories.
If this doesn't work don't run your emacs sudo
like suggested by some people over there, rather use emacs on the command line with
$ emacs -nw
or use another editor for the time being.
My crystal ball tells me that this might get fixed not too far in the future.
Best Answer
None of those is expressible in a terminal program; you'll need a GUI (Aqua or X11) version of Emacs to use them.