2

I usually ssh into a machine at my university and run emacs on screen. I want to figure out what unicode strings code for a particular command ? For example when I changed the preferences in my OSX terminal app and associated the following actions to keyboard buttons then Emacs interpreted them as useful command.

Button  Action  Keystroke
end     \005    CTRL+e
home    \001    CTRL+a
pgdown  \026    CTRL+v
pgup    \033v   ESC v

I want to make more such bindings. For example if I could find out the right action for "Ctrl+_"(Undo) then I could associate that to one of the useless function keys.

So basically how can I find out what "Action" triggers a Keystroke ?

1

Two steps:

  1. In any buffer, do a quoted insert of the key sequence. For example:

    C-q C-e

    Instead of calling move-end-of-line (the command that C-e is bound to by default), Emacs will insert ^E at point.

  2. Hit C-b to put point on the character you just inserted, then do C-x = (bound to what-cursor-position). Emacs will print relevant information about the character at point in the minibuffer. For ^E, you'll see this:

    Char: C-e (5, #o5, #x5) point=1 of 1 (0%) column=0

    This tells you that the character code for C-e is 5 in octal, #o5 in decimal, and #x5 in hex.

Following these steps for the other key sequences you listed, it looks like "Actions" are derived from the decimal notation:

| Key Sequence | Output of C-x =               | Action |
|--------------+-------------------------------+--------|
| ^E           | Char: C-e (5, #o5, #x5)       | \005   |
| ^A           | Char: C-a (1, #o1, #x1)       | \001   |
| ^V           | Char: C-v (22, #o26, #x16)    | \026   |
| ^[           | Char: ESC (27, #o33, #x1b)    | \033   |
|--------------+-------------------------------+--------|

In short:

| Char code | Action |
|-----------+--------|
| #o5       | \005   |
| #o1       | \001   |
| #o26      | \026   |
| #o33      | \033   |
|-----------+--------|

So you'll need to follow this pattern when determining the correct "Action" for a given char code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.