Inserting Control Characters in GNU Emacs' Minibuffer

May 24, 2022 20:56 · 185 words · 1 minute read emacs

Most commands in GNU Emacs are entered in a special buffer called the minibuffer. Usually, it appears at the bottom of a frame (Read and learn more about the minibuffer here and here).

Sometimes, when using the minibuffer, you may want to enter control characters. An example of a use-case where you may want to use control characters is when you have configured your editor to visually see linefeed characters—“^M”—and you want to use a facility like GNU Emacs’ isearch to manually replace that character with something else. To do so, use the in-built function: (quoted-insert ARG) which is normally bound to “C-q”. This reads the next input character and inserts it—a useful thing when inserting control characters. Here’s an example how to insert a newline control sequence:

C-q C-j

For what’s it worth, you can use octal digits to specify a character code too! Note that while inputting characters, non-digit characters terminate the sequence.

In summary, the important thing to note is that you can use quoted-insert (usually bound to “C-q”) to insert any control character anywhere you want, and that includes the minibuffer.